Exclude all directory files, BUT, include all sub-directory files

What is the problem you are having with rclone?

I want to exclude all files in a directory, but include all sub-directories and sub-directory files. Let me present an example.

I have a directory named dir with two files (file1 & file2), and one subdirectory named subdir. The subdir directory contains one file named file3.

dir
  |-- file1
  |-- file2
  |-- subdir
         +-- file3

I want to exclude all files in the dir directory (file1, file2, etc.), while including all sub-directories, and all files in the sub-directories of dir (subdir/file3).

Run the command 'rclone version' and share the full output of the command.

rclone v1.50.2

  • os/arch: linux/amd64
  • go version: go1.13.8

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

Google Drive

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

rclone sync -n ~/path/to/dir/ gdrive:backup --exclude "dir/**"

This command excludes everything. How do I exclude only the files in the directory, but keep sub-directories, and sub-directory files?

Note that this excludes all files in dirctories called dir, if you want a specific directory called dir in the root then use /dir/**.

If you only want to exclude files in the directory and not subdirectories then --exclude /dir/* should do it.

You can test with rclone lsf -R gdrive:backup --exclude "/dir/*" or with rclone sync -n like you have been doing.

1 Like

I did this as the exclude only didn't work:

felix@gemini:~/test$ rclone ls /home/felix/test
        0 file1
        0 file2
        0 subdir/file3
felix@gemini:~/test$ rclone ls /home/felix/test --filter '+ subdir/**' --filter '- **'
        0 subdir/file3


felix@gemini:~/test$ rclone ls /home/felix/test --exclude '/dir/*'
        0 file1
        0 file2
        0 subdir/file3
2 Likes

I was able to get both solutions to work, I just had to go up one directory higher and run things from the home directory, instead of the /test directory

felix@gemini:~$ rclone ls /home/felix/test
        0 file1
        0 file2
        0 subdir/file3

felix@gemini:~$ rclone ls /home/felix/test --filter '+ subdir/**' --filter '- **'
        0 subdir/file3

felix@gemini:~$ rclone ls /home/felix/test --exclude '/dir/*'
        0 subdir/file3
1 Like

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