How to configure .stignore to first ignore all and then specify desired files and directories?

I have more directories and files I want to ignore than I want synced, and anyway, it makes more sense for me NOT to sync every new directory I create. So basically I want to do something like (a bit like you would in .htaccess):


INCLUDE Folder 1

INCLUDE Folder 2


I tried putting an .stignore file in the directory in which I want to ignore everything initially like this:

/* # first ignore all files, directories and subdirectories
// now explicitly name the directories I want using exclamation mark directive

!/1. My first folder/
!/2. My second folder/
# NOT 3. My third folder/
!/4. My fourth folder/subfolder/


What am I doing wrong here? Syncthing is going ahead and syncing EVERYTHING in this folder and its subfolders, seems like the initial “ignore all” directive isn’t being followed, maybe my order or syntax is iffy somewhere - is the “/*” not right?

I could only find one thread vaguely related but it didn’t seem to answer the question. I thought maybe I should do the “Exclude All” directive AFTER I have named the “included” directories, but that doesn’t explain why it would go ahead and sync everything else anyway.

First of all, the order. The first match counts, top to bottom. So an ‘ignore all/rest’ should be the last element.

Secondly, I think your ignore-all is actually incorrect (if the supplied line is the one you actually use). Removing the # ... should sort that, as it now most likely tries to match * # first ignore all files, directories and subdirectories in the root of the folder instead of acting like a wild card (and as a side-note, the third folder should be a proper comment using // instead of #).

This has come up before and I wouldn’t be surprised if here it’s also because of in the Docs which uses all those # lines that look like valid comments that you can put inside the .stignore file (but they are not).

By Jove I think you got it. There was nothing in the log to say that .stignore was not being parsed correctly or anything, but sure enough I got rid of the #comments, and moved the “ignore all” directive down to below the “don’t ignore” directives and I think we are in business now! You are telling me that a # is not a legitimate comment marker at all?! I know it doesn’t mention it in the docs, only ‘//’ but well, I guess I did KINDA assume it was valid being as they put it in their code examples…! Who does that?

Thanks for the help.

Yes, the # character is nothing special. In fact, it can be used as a legitimate part of a filename too. Also, only lines that begin with // are treated as comments, meaning that you can’t place comments in other places, e.g. after a filename.

Not that that matters too much, though. So entering # this is a comment will match and ignore a file named # this is a comment, which is usually more or less functionally equivalent to it being a comment in the first place. :slight_smile:

I think # was a comment character initially, or perhaps was intended to be one.

If it’s used on the first column, yes it doesn’t really matter. But our examples place it on the same line, after an actual ignore pattern. The typeface is different, but it does provoke the assumption of being a legitimate comment syntax.

Yeah that’s badly done.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.