Unison: Ignore all files with *.ext, except those in a specific subdirectory

unison

I am trying to perform a sync using Unison (2.40.102) where I want to ignore all files with a specific extension, say *.ext, but not ignore the files with this extension if they are in a specific subfolder.

Folder structure:

main_dir
|file.ext
|...
|--sub_dir_1
   |more_files.ext
   |...
|--sub_dir_2
   |even_more_files.ext
   |...
   |--dir_I_want_to_sync
      |sync_this_file1.ext
      |...
      |sync_this_fileN.ext
      |--some_arbitrarily_named_dir
         |also_sync_this.ext
         |...
         |--more_arbitrarily_named_dirs_with_ext_files_in_them
            |...

As the folder structure is not constant, I cannot just ignore only specific paths, but have to do this very generally. My idea was to first ignore all the files with the extension *.ext and then un-ignore the ones below dir_I_want_to_sync.
However, that is were I am failing to find the right command…

The relevant parts of my profile file look like this:

# Ignore all files with extension *.ext
ignore = Name {.,}*{.ext}

# Try to not ignore the files within the subdirectory (NOT WORKING)
ignorenot = Path */dir_I_want_to_sync/*             # 1)
ignorenot = Name */dir_I_want_to_sync/{*/}*{.ext}   # 2)

Remarks:
1) Does not do anything, because the files are ignored by their filename, not their path
2) Was meant to reverse the ignore on all the files in dir_I_want_to_sync, but it does not catch all subfolders.

Is there any way to apply the ignorenot = Name ... to a file regardless of how deep it is in the directory structure, as long as it is below a directory with a specific name?

(I hope, this was not too confusing. I am happy to clarify!)

Best Answer

Use Regex instead of Path when you need to match an arbitrary directory depth.

ignore = Name *.ext
ignorenot = Regex .*/dir_I_want_to_sync/.*\.ext
Related Question