Exclude certain directories from --delete-empty-src-dirs

What is the problem you are having with rclone?

Noticed a lot of passer / sleeps. Along with trying to:
Kee certain directories not being deleted from Sorce as they are used and tied to the folder id for my custom python script I don't really see a way to exclude or filter-from so certian root directories aren't deleted without resorting to

rclone rmdirs remote:root1/movies --leave-root
rclone rmdirs remote:root1/shows --leave-root
rclone rmdirs remote:root2/movies --leave-root
rclone rmdirs remote:root2/shows --leave-root
etc...

2021/12/05 19:16:15 NOTICE: A-Library/Movies: Skipped remove directory as --dry-run is set
2021/12/05 19:16:15 NOTICE: A-Library: Skipped remove directory as --dry-run is set

What is your rclone version (output from rclone version)

Windows (Actual os version: Microsoft Windows 11 Pro for Workstations 2009 (64 bit)

rclone v1.57.0

  • os/version: Microsoft Windows 10 Pro for Workstations 2009 (64 bit)
  • os/kernel: 10.0.22000.348 (x86_64)
  • os/type: windows
  • os/arch: amd64
  • go/version: go1.17.2
  • go/linking: dynamic
  • go/tags: cmount

Which cloud storage system are you using? (eg Google Drive)

Google Drive but local also.

The command you were trying to run (eg rclone copy /tmp remote:tmp)

rclone move GSDLM0: "GMDmedia:/Media Library" -L -P --ignore-case-sync --delete-empty-src-dirs --fast-list --drive-chunk-size 128m --buffer-size 16m --log-file "C:\Users\PC\Desktop\TestLog.log" -vv --crypt-server-side-across-configs --dry-run

The rclone config contents with secrets removed.

Not relevant and crypted.

A log from the command with the -vv flag

ZeroBin.net - log file

have tried using --filter-from "C:\Users\PC\Desktop\Folder.Filter"

- Folder.Drives
- #Temp/Folder.Drives
- A-Library/Shows/Folder.Drives
- A-Library/Movies/Folder.Drives
- K-Library/Shows/Folder.Drives
- K-Library/Movies/Folder.Drives
- S-Library/Shows/Folder.Drives
- S-Library/Movies/Folder.Drives
+ *

and placing the same file in those directories but still keeps deleting them with dry run.

I ran the script with and without the filter applied and searching for them did apear in the one without the filter. but either way it still deletes the root folders when a file is in the path even if its set to be ignored and not moved.

2021/12/05 22:23:44 NOTICE: A-Library/Shows/Folder.Drives: Skipped move as --dry-run is set (size 5)
2021/12/05 22:23:44 NOTICE: K-Library/Movies/Folder.Drives: Skipped move as --dry-run is set (size 5)
2021/12/05 22:23:44 NOTICE: #Temp/Folder.Drives: Skipped move as --dry-run is set (size 5)
2021/12/05 22:23:44 NOTICE: K-Library/Shows/Folder.Drives: Skipped move as --dry-run is set (size 5)
2021/12/05 22:23:44 NOTICE: S-Library/Shows/Folder.Drives: Skipped move as --dry-run is set (size 5)
2021/12/05 22:23:44 NOTICE: A-Library/Movies/Folder.Drives: Skipped move as --dry-run is set (size 5)
2021/12/05 22:23:44 NOTICE: S-Library/Movies/Folder.Drives: Skipped move as --dry-run is set (size 5)

with --filter in the command:

2021/12/05 22:23:44 NOTICE: A-Library/Movies: Skipped remove directory as --dry-run is set
2021/12/05 22:23:44 NOTICE: A-Library: Skipped remove directory as --dry-run is set
2021/12/05 22:23:44 NOTICE: #Temp: Skipped remove directory as --dry-run is set

So you want to filter it out from the move command as well?

Can you share the full command you are running? Just use rclone ls for testing as well.

I went ahead and moved it to the first command so different remotes but same process, and same file tree/files that are needed to stay as "placeholders" so the directories aren't deleted. just not a crypted mount for simplicity as those are the actual folder ids that I need to preserve.
Command: would be removing dry run after testing.

rclone move GSDLC: GSDLM: --filter-from "C:\Users\PC\Desktop\Folder.Filter" -L -P --ignore-case-sync --fast-list --delete-empty-src-dirs --fast-list --drive-chunk-size 128m --buffer-size 16m --log-file "C:\Users\PC\Desktop\TestLog.log" -vv --dry-run

LS:

What I'm asking is run rclone ls with your filters for testing rather than move as you can see what shows up in the ls rather than trying move something or dry run it.

Are those directories?

You want to do it like this:

https://rclone.org/filtering/#how-filter-rules-are-applied-to-directories

- /Folder.Drives/
- /#Temp/Folder.Drives/
- /A-Library/Shows/Folder.Drives/
- /A-Library/Movies/Folder.Drives/
- /K-Library/Shows/Folder.Drives/
- /K-Library/Movies/Folder.Drives/
- /S-Library/Shows/Folder.Drives/
- /S-Library/Movies/Folder.Drives/
+ *

there not directories no. they are pointing to actual files to try and force them to not be empty so --delete-empty-src-dirs won't delete them because in theory they won't be empty if those files are excluded from being moved.

and oh okay, let me do that one second.

LS With Filter:
C:\Users\PC>rclone ls GSDLC: --filter-from "C:\Users\PC\Desktop\Folder.Filter" - Pastebin.com

running the ls with the filter it does apply and those files no longer show up in the ls, or in a move command however when i run the actual command it ignores said filter and deletes those directories anyways.
The Folder.Filter file is only 5bytes if that matters at all.

Can you share your updated filter file, rclone ls command with -vv and rclone sync command with -vv --dry-run and share the full output for each.

Filter File is still the same:

- Folder.Drives
- #Temp/Folder.Drives
- A-Library/Shows/Folder.Drives
- A-Library/Movies/Folder.Drives
- K-Library/Shows/Folder.Drives
- K-Library/Movies/Folder.Drives
- S-Library/Shows/Folder.Drives
- S-Library/Movies/Folder.Drives
+ *

Wouldn't be any point to sync as its just a temp directory tree that gets moved to the crypt part of the drive then moved to my drive and would delete what was moved if i take off dry run but.

LS command:

https://pastebin.com/Dm5sJ5kP

rclone sync with dry run:


C:\Users\PC>rclone sync GSDLC: GSDLM: --filter-from "C:\Users\PC\Desktop\Folder.Filter" -L -P --ignore-case-sync --fast-list --delete-empty-src-dirs --fast-list --drive-chunk-size 128m --buffer-size 16m --log-file "C:\Users\PC\Desktop\TestLog.log" -vv --dry-run
Error: unknown flag: --delete-empty-src-dirs
Usage:
  rclone sync source:path dest:path [flags]

Flags:
      --create-empty-src-dirs   Create empty source dirs on destination after sync
  -h, --help                    help for sync

Use "rclone [command] --help" for more information about a command.
Use "rclone help flags" for to see the global flags.
Use "rclone help backends" for a list of supported services.

2021/12/06 08:22:29 Fatal error: unknown flag: --delete-empty-src-dirs

C:\Users\PC>

log is empty.

rclone move log:

https://zerobin.net/?f3cac109cb3ee8a4#pg4zD7aYtM+/O8pNpEuaz1C2k2SzvIRFVsKDy2FYgpo=

on both ls and the move it is showing:

2021/12/06 08:15:12 DEBUG : A-Library/Shows/Folder.Drives: Excluded from sync (and deletion)
2021/12/06 08:15:12 DEBUG : A-Library/Movies/Folder.Drives: Excluded from sync (and deletion)
2021/12/06 08:15:12 DEBUG : S-Library/Movies/Folder.Drives: Excluded from sync (and deletion)
2021/12/06 08:15:12 DEBUG : S-Library/Shows/Folder.Drives: Excluded from sync (and deletion)
2021/12/06 08:15:12 DEBUG : #Temp/Folder.Drives: Excluded from sync (and deletion)
2021/12/06 08:15:12 DEBUG : K-Library/Shows/Folder.Drives: Excluded from sync (and deletion)
2021/12/06 08:15:12 DEBUG : K-Library/Movies/Folder.Drives: Excluded from sync (and deletion)

but at the end its still showing it wanting to delete the folders those files reside in.

That only works with move so that's an expected error. Sync makes destination look like source so that flag wouldn't make sense for it.

You really should make your own client ID/secret as you are getting a lot of rate limits.

Where do you see it wants to delete them?

at the very bottom:

2021/12/06 08:38:44 NOTICE: A-Library/Movies: Skipped remove directory as --dry-run is set
2021/12/06 08:38:44 NOTICE: A-Library: Skipped remove directory as --dry-run is set
2021/12/06 08:38:44 NOTICE: #Temp: Skipped remove directory as --dry-run is set
2021/12/06 08:38:44 DEBUG : root '': deleted 1644 directories
2021/12/06 08:38:44 INFO  : There was nothing to transfer
2021/12/06 08:38:44 NOTICE: 
Transferred:   	    8.727 TiB / 8.727 TiB, 100%, 0 B/s, ETA -
Checks:               400 / 400, 100%
Deleted:                0 (files), 1644 (dirs)
Renamed:              397
Elapsed time:      1m38.3s

i am using my own client and secret.

Since you neglected the rclone.conf, I had to guess. Are you seeing API hits on it?

So let's take one filter, you have:

A-Library/Movies/Folder.Drives

So that excludes it from the move and deletion.

So if that folder is excluded and A-Library/Movies is empty (no files) and A-Library is empty (no files), it would remove it since you've excluded it and they are empty as you've moved all the files with the move command.

I think it's doing exactly what you asked, but not what you want it to do.

I think you'd be better off with this maybe:

https://rclone.org/filtering/#exclude-directory-based-on-a-file

You can leave a .ignore file or something to not remove it.

however here is a dashboard image of the month: https://i.imgur.com/Ax0bnLX.png

Google Drive API	810,759	errors: 13			
Compute Engine API	684,771 errors: 0

again, not a folder. it's an actual 5byte file used for placeholding.

Again, it doesn't matter if it's a file or directory as it's excluded.

So when you exclude, you have empty directories that get deleted because of your previous exclusion.

So my only workaround would be to run rclone rmdirs, there is just no log for it. (for info, without debug)

# Clean Empty Dirs
rclone rmdirs GSDLC:#Temp/ --leave-root 
rclone rmdirs GSDLC:A-Library/Shows/ --leave-root 
rclone rmdirs GSDLC:A-Library/Movies/ --leave-root 
rclone rmdirs GSDLC:K-Library/Shows/ --leave-root 
rclone rmdirs GSDLC:K-Library/Movies/ --leave-root 
rclone rmdirs GSDLC:S-Library/Shows/ --leave-root 
rclone rmdirs GSDLC:S-Library/Movies/ --leave-root 

So I personally wouldn't do this but in reality, if you exclude a file and you try to remove a directory that rclone thinks is empty but a file is there, it'll error out:

felix@gemini:~$ rclone move /home/felix/test /home/felix/test1 -vv --exclude "A-Library/Movies/Folder.Drives"
2021/12/06 11:33:13 DEBUG : Setting --config "/opt/rclone/rclone.conf" from environment variable RCLONE_CONFIG="/opt/rclone/rclone.conf"
2021/12/06 11:33:13 DEBUG : rclone: Version "v1.57.0" starting with parameters ["rclone" "move" "/home/felix/test" "/home/felix/test1" "-vv" "--exclude" "A-Library/Movies/Folder.Drives"]
2021/12/06 11:33:13 DEBUG : Creating backend with remote "/home/felix/test"
2021/12/06 11:33:13 DEBUG : Using config file from "/opt/rclone/rclone.conf"
2021/12/06 11:33:13 DEBUG : Creating backend with remote "/home/felix/test1"
2021/12/06 11:33:13 DEBUG : A-Library/Movies/Folder.Drives: Excluded
2021/12/06 11:33:13 DEBUG : Local file system at /home/felix/test1: Waiting for checks to finish
2021/12/06 11:33:13 DEBUG : Local file system at /home/felix/test1: Waiting for transfers to finish
2021/12/06 11:33:13 INFO  : There was nothing to transfer
2021/12/06 11:33:13 INFO  :
Transferred:   	          0 B / 0 B, -, 0 B/s, ETA -
Elapsed time:         0.0s

2021/12/06 11:33:13 DEBUG : 3 go routines active
felix@gemini:~$ cd test
felix@gemini:~/test$ ls
A-Library  one  two
felix@gemini:~/test$ cd ..
felix@gemini:~$
felix@gemini:~$ cd
felix@gemini:~$ rclone move /home/felix/test /home/felix/test1 -vv --exclude "A-Library/Movies/Folder.Drives" --delete-empty-src-dirs
2021/12/06 11:34:53 DEBUG : Setting --config "/opt/rclone/rclone.conf" from environment variable RCLONE_CONFIG="/opt/rclone/rclone.conf"
2021/12/06 11:34:53 DEBUG : rclone: Version "v1.57.0" starting with parameters ["rclone" "move" "/home/felix/test" "/home/felix/test1" "-vv" "--exclude" "A-Library/Movies/Folder.Drives" "--delete-empty-src-dirs"]
2021/12/06 11:34:53 DEBUG : Creating backend with remote "/home/felix/test"
2021/12/06 11:34:53 DEBUG : Using config file from "/opt/rclone/rclone.conf"
2021/12/06 11:34:53 DEBUG : Creating backend with remote "/home/felix/test1"
2021/12/06 11:34:53 DEBUG : A-Library/Movies/Folder.Drives: Excluded
2021/12/06 11:34:53 DEBUG : Local file system at /home/felix/test1: Waiting for checks to finish
2021/12/06 11:34:53 DEBUG : Local file system at /home/felix/test1: Waiting for transfers to finish
2021/12/06 11:34:53 INFO  : two: Removing directory
2021/12/06 11:34:53 INFO  : one: Removing directory
2021/12/06 11:34:53 INFO  : A-Library/Movies: Removing directory
2021/12/06 11:34:53 DEBUG : A-Library/Movies: Failed to Rmdir: remove /home/felix/test/A-Library/Movies: directory not empty
2021/12/06 11:34:53 INFO  : A-Library: Removing directory
2021/12/06 11:34:53 DEBUG : A-Library: Failed to Rmdir: remove /home/felix/test/A-Library: directory not empty
2021/12/06 11:34:53 DEBUG : Local file system at /home/felix/test: failed to delete 2 directories
2021/12/06 11:34:53 DEBUG : Local file system at /home/felix/test: deleted 2 directories
2021/12/06 11:34:53 INFO  : There was nothing to transfer
2021/12/06 11:34:53 INFO  :
Transferred:   	          0 B / 0 B, -, 0 B/s, ETA -
Deleted:                0 (files), 4 (dirs)
Elapsed time:         0.0s

2021/12/06 11:34:53 DEBUG : 2 go routines active
felix@gemini:~$ cd test
felix@gemini:~/test$ ls
A-Library

That's an example of not using that flag.

It generates an error, which for me isn't ideal.

The problems lies with you are excluding it so rclone based on what your ask is says the directory is now empty and tries to remove it.

That'll be the same with any exclusion you do.

I'm a bit confused why you are using that flag at all though.

Do you just have empty directories on the source that are creating an issue?

correct. I never bothered to clean the empty folders, and nor googledrive via web or onecommader will load them as its just to many files and freezes / sorting is an issue with all the empty directories as they are there for just a temp/cache. + i need to move them to #temp to rename the folders for sonarr/radarr to scan them in. then move them to the directory either:

A- anime 
K- korean/other languages
S- normal language/netflix etc. 

they are on a share drive because thats the only way i can clone them then moved off and re crypted to that same share drive and moved off to the main directory. i can just run the --delete-empty-src-dirs on the crypt portion as those are auto defaulted back with no merge conflicts. the Cache remote is the issue as i need to keep the folder ids the same.

It is a share drive owned by me, so I don't have the feature of just wiping it with empty trash either (unlike My Drive) if I could force it to remove everything except the root folders listed.

exactly. the reason behind clearing those empty directories is because google drive web can't walk them all.

I can make the mount walk them all but I don't mount the drives to the vps. only on Windows for playback etc and eventually Linux by using:
start rclone --no-console mount --file-perms 0777 GMDmedia:\ C:\.Mounts\Media --no-modtime --rc --rc-addr=:3750 --vfs-cache-mode writes --vfs-cache-max-age 5h --vfs-write-back 5s --cache-dir x:\rclone --dir-cache-time 5m

rclone rc vfs/refresh recursive=true --rc-addr=:7530 --timeout 15m -q
Not sure if i need _async=true though to make it walk the tree and prime the cache or if without, will still work.

--delete-empty-src-dirs probably shouldn't be trying to delete non-empty folders (or raising an error when they are non-empty) in the first place.

It seems like manually deleting subfolders (with rmdirs) is your best option. I don't see how this functionality could be easily added to --delete-empty-src-dirs. Would rclone need a second layer of excludes? That seems cumbersome.