How to copy folders in a batch?

I have a directory in which there are many folders but i do not want to copy all of them at once i want to copy say 10 folders at a time from drive to local but i don't know how can i do it.

hello and welcome to the forum,

there are a few ways to do that.

  1. create a batch file like so

rclone copy /path/to/local/folder1 dest:/folder1
rclone copy /path/to/local/folder2 dest:/folder2
rclone copy /path/to/local/folder3 dest:/folder3
rclone copy /path/to/local/folder4 dest:/folder4

  1. use flag --include-from
    https://rclone.org/filtering/#include-from-read-include-patterns-from-file

let says you want to copy folders folder2 and folder3
create a text file named include.txt

/folder2/**
/folder3/**

rclone copy path/to/local dest: --filter-from=include.txt

1 Like

Hello thanks for the reply
Is there a way to get the directory list in this format /folder/** when i used rclone lsf --dirs-only i got the directory list in this format folder/ do i have to manually add /** for each directory name in the include list?

you should be able to.
give it a try.

i suggest when testing to use this flag
--dry-run

here is an example of a command i have used.

rclone lsf --files-only -R %dest% | rclone copyto %source% %dest% --include-from=- -v

Sorry i think i didn't write my reply properly I wanted to say when i used lsf --dirs-only i got the directory list in this format

folder/
folder2/
folder3/

but in the include list you have to format folders like this

/folder/**
/folder2/**
/folder3/**

So do i have to add /** to every directory name in the include list manually? but there are too many folders in my directory so is there any way to get the directory list in /folder/** format so i can just copy the directory names from cmd and paste it in the include list?

Are you on Windows?

If you want to use rclone lsf, and produce path strings in format /folder/**, you could do something like the following:

From Command Prompt:
for /f %i in ('rclone lsf ENTER_SOURCE_PATH_HERE --dirs-only') DO @echo /%i**

Alternatively, from PowerShell:
rclone lsf ENTER_SOURCE_PATH_HERE --dirs-only | % { "/${_}**" }

If you are going to manually maintain the include list files anyway, it would be just as quick to just copy the paths as returned by rclone lsf, and then use a proper text editor like Notepad++ and either perform regex search/replace (search for ^(.*), replace with /\1**) or multi-cursor editing (Alt+Shift+PageDown etc).

1 Like

also on windows you can do this

rclone lsf --dirs-only C:/path/to/local/folder --absolute --max-depth=1 | wsl sed 's~/$~/**~' | rclone sync C:/path/to/local/folder remote: --include-from=- -vv

on linux, from user calisro
rclone lsf --dirs-only \path\to\local\folder | sed 's~/$~/**~' | rclone sync --include-from - \path\to\local\folder remote:

It think it was correct as I wrote it, assuming you execute it directly from Command Prompt, interactive shell. You are correct, though, when executed from a batch script - then you would need to double up the '%':

for /f %%i in ('rclone lsf ENTER_SOURCE_PATH_HERE --dirs-only') DO @echo /%%i**

1 Like

Thank you so much it worked

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