Sync only certain files with Ignore Patterns

I have a directory tree like the following on my Windows PC:

Root dir
 + SubDir1
    - file1.txt
    - file2.txt
 + SubDir2
    - someotherfile.txt
 - backup1.rar
 - backup2.rar
 - backup3.rar
 - BackupFull.rar
 - somethingelse.rar

The only files I want to sync are the ones beginning with backup (case-insensitive). I thought about using the .stignore file for that, but so far, my attempts to do so have all failed. I tried:

// First try

// Second try

// Third try

So, what is the correct way?

note: found this but that’s different because OP wants to sync files inside a subfolder while mine are in the root directory.

Thanks anyone

Edit The following seems to work:


Two oddities:
1- The first line makes both files beginning with backup and Backup to sync. This is unexpected! If I use (?i)!/backup* instead, it wont work.
2- Switching lines 2 and 3 causes it to stop working. Why is that?

You’re making it rather complex… I just set up that same structure and tested it, the following patterns work for me:


The patterns are case insensitive by default on operating systems where that makes sense, i.e. Mac and Windows.

Be aware that only will work if its at the root of the directory.

@calmh: Thanks! Btw that looks like my first attempt (I forgot to include), which was:


There seems to be no mention of that in the docs, but anyway, I feel that the pattern using (?i) should work as well - but it doesn’t. There are also a few other places where it would make sense to behave in a case-insensitive manner on proper OSes, for consistency, so I’d vote for that.

I don’t have the code in front of me, but I suspect that what happens is that your (?i)backup actually gets turned into (?i)(?i)backup on case insensitive OS:es, which then doesn’t work. It should work, of course, so that’s a bug in that case.

I came across a similar problem (and exactly the same issue with Windows and (?i)

Bug reported there

It won’t turn into (?i)(?i), link. However, it could turn into (?i)*(?i) because of the TrimPrefix… I think the documentation should state that (?i) should be stated in front because some ppl might want to filter myfolder with (?i) in its name.