how to exclude all subfolders

Don’t know if I was blind, but I did not find how to exclude all subdirectories and only sync the files in the root folder. Neither in the FAQ nor in the documentation, and all forum threads seem to have more complex topics than this seemingly easy question. My own tries with

"!/*

*"

(include all items in the current root folder, exclude everything) were not successful.

How can I do it?

1 Like

I don’t think you can as there is no distinction between files and folders in the ignore system. So you will have to list out one or the other.

So you either ignore everything at the root, or unignore everythng at the root.

Perhaps try just:

/*/**

Which says ignore everything that has a slash in it, which should exclude everything from level 2 onwards.

Then you might end up with the files and empty directories from the root. But I am not sure this will work.

1 Like

Have similar situation in rsync. Solution was including what wanted and finishing with a rule excluding all. rsync follows rules in order (first rules have priority over latter ones). If this is the case with Syncthing (someone will clarify shortly but the docs infer that this is the case) could use the include “!” directive for everything in root followed by an ignore all directive.

Example:

! /*
*
1 Like

But this include directive includes directories and their content.

1 Like

The docs state:

A pattern beginning with / matches in the current directory only. /foo matches foo but not subdir/foo.

and

Please note that directory patterns ending with a slash some/directory/ matches the content of the directory, but not the directory itself. If you want the pattern to match the directory and its content, make sure it does not have a / at the end of the pattern.

Maybe

! /*/

It may get a little complicated (rysnc did too), and obviously do not have exact answer, but using above logic end goal should be possible.

The first quote is just about matching at the root level, the second quote says the opposite of what’s needed: With a trailing slash the directory itself is not matched. @AudriusButkevicius proposal /*/ (trailing ** does nothing) is the simplest option. It does sync the directories at root, but not their content, which should be acceptable.

Your example !/* * doesn’t work (as also pointed out by @AudriusButkevicius), because !/* matches everything in the root and thus also their child items.

1 Like

I think something like

!*.*
*

in the exclude file should do it. It’s a light version of a line I use in my exclude file that under other excludes all files but one type. But whatever I do, I still have the first level content included with this.

Wont work on newer versions, as the first pattern will include each and every file with a dot in it regardless of level.

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