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):
IGNORE ALL
INCLUDE Folder 1
INCLUDE Folder 2
etc.
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/
etc...
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 https://docs.syncthing.net/users/ignoring.html#example 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?
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.
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.