Can't get --exclude working after --include


I’m trying to filter remote directories and move them to a subdirectory with the corresponding first letter, i.e. /MyFolder, /MoveMe, /MatchingFolder -> /M/ - basically trying to organise all my media folders based on their first letter. The problem is that by default --include /{M*}/ includes the subfolder itself so rclone gives error that remotes overlap. So I thought --exclude to the rescue with --exclude /M/. The problem is that I can’t get it to work.

The exclude works on it’s own, without the include, but not after the include. So see this example:

rclone lsd ~/ --include /{M*}/ --exclude /M/ --dump-filters
--- start filters ---
--- File filter rules ---
- ^.*$
--- Directory filter rules ---
+ ^(M[^/]*)/$
- ^M/$
- ^.*$
--- end filters ---
           0 2017-01-10 12:46:56         0 Music
           0 2017-06-30 12:07:09         0 Movies
           0 2017-10-21 16:08:10         0 M

What am I doing wrong here and how could I filter out the M in this case?


Due to the command line config parser I use, it parses all the --includes before the --excludes (or maybe the other way round), so this won’t work. It does say this in the docs, but maybe it isn’t obvious enough!

Anyway, use --filter '- /M/' --filter '+ /{M*}/' instead and it will work fine hopefully.

What I should probably do is make a warning - not sure why I didn’t think of that before! I made an issue.

1 Like

Ah! Yeah I did read all the filter docs and I understood it to mean: first --includes and then --excludes are redacted, including from the --includes. I did try with the filters but same result due to misunderstanding :blush:

Thanks for clearing that up, will try with that.

@ncw Sorry, I just can’t get the --filter working at all. The include works as it should, but not --filter. Here’s the command I run and it outputs every single directory, not just starting with ‘M’:

rclone lsd STORM-CRYPT:Media/Plex/Films --filter '+ /{M*}/' -vvv

rclone: Version "v1.38" starting with parameters ["rclone" "lsd" "STORM-CRYPT:Media/Plex/Films" "--filter" "+ /{M*}/" "-vvv"]

I’m assuming --filter works with directories, as well as files?

edit: in contrast, this lists only directories starting with ‘M’ :
rclone lsd STORM-CRYPT:Media/Plex/Films --include /{M*}/

edit 2: Argh, I can’t get the move command to work even with the --include:, what is wrong with this command?:
rclone move STORM-CRYPT:Media/Plex/Films STORM-CRYPT:Media/Plex/organise/A --include '/{A*}/' -vv --dry-run

Every single directory gives Excluded from sync (and deletion), including those starting with A

The reason that works, but your --filter doesn’t is that the --include puts in an exclude everything rule at the end, whereas the filter doesnt.


--filter '+ /{M*}/' --filter '- *'

Will work

The reason that doesn’t work is that you are only matching the directories with the filter, you need --include '/{A*}/**' to match the contents.