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:


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)

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!)

  • Try ignorenot = Regex */dir_I_want_to_sync/.*\.ext. Please let me know if this works. – Mike Pierce May 12 '16 at 19:19
  • Or potentially better, try ignorenot = BelowPath full/path/to/the/dir_I_want_to_sync/with/ext/files/underneath/{.*,*}.ext. Note that in a Path the * matches any string of characters except the / character, so you can't use it to represent arbitrary paths. – Mike Pierce May 12 '16 at 19:34
  • @mapierce271 Ah, so that's why 2)did not work! Thanks for your note. In the Regex it seems like the initial . is missing, right? – compare to @Gilles answer. Unfortunately, I could not get the BelowPath to work, although it seems like a handy option as well! But the Regex did the job, thanks! :) – blsqr May 13 '16 at 9:14

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.