You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Copy entire directory structure, not just the contents #1228
Hi, I'm trying to copy a directory but the copy command appears to only copy the contents and not the entire directory structure which is what I want:
So I have a directory dir1
dir1/
--file1
--file2
And want to copy it exactly to src/:
src/
--dir1
and not strip of its folder name like this:
src/
--file1
--file1
The command I am using is copy src remote:src. I've also tried copyto and it still copies the contents only. How can I make this work?
What is your rclone version (eg output from rclone -V)
rclone v1.35-40-gb6848a3β
Which OS you are using and how many bits (eg Windows 7, 64 bit)
OSX
Which cloud storage system are you using? (eg Google Drive)
Google drive
Reacted by Heiko, Long, Yi Liu, Prashanth Thiruppathi, halffunction, Balazs Erdos, r3dnck, Ken Chen and Bas van den Wollenberg
Please read my post again. I tried that command and it only copies the contents and subdirs without including the root folder itself. Not sure if this is a bug or if that's the intended behavior. If so, any way to work around it? Including folder should be the default IMO since that 'the default behavior of the cp command. If I wanted to copy only the contents I would have done srcdir/ remote:dest with the forward slash at the end.
rclone should definitely copy exactly what we tell it, not just the contents, so dir for whole dir and dir/ for just the contents. The behaviour should be amended.
Reacted by Heiko, Yi Liu, Prashanth Thiruppathi, Ivan P, Czechball, Sahib Bhai, Victor Engmark, red thing, benny1611, Alexis and 8 more
ncw doing copy dir1 remote:src/dir1 still copies the contents and doesnt preserve foldername.
Doing copy dir1 remote:src/newDirName/ only works for a specified dirname an when the dir exists on google drive.
Any chance you could implement this simple feature? It's just the case that preserving the directory name is extremely important in my case and im sure others might find that helpful at some point
changed the title [-]Copy entire directory structure, not just its contents[/-][+]Copy entire directory structure, not just the contents[/+]on May 12, 2017
I'm having this issue. I'm experienced with rsync, and the behavior is not the same. With rsync, if you remove the tailing / from the source path, it tells rclone to copy also the source directory instead of just it's contents. @ncw, is there any way that we can make rclone behave the same in that regard? Would be nice to be able to copy directories without having to name them in the dest path. By the way, I'm not criticizing. Just thinking out loud. Thanks for the great tool!!!
Reacted by Arnaldo Gabriel, Alexis, Gui Ambros, Ivan L and Fox
+1 for this. Rclone is a great tool, but it should have a basic function like this implemented. @ncw, would be great to have this feature. Thanks for your hard work on this tool. I will be donating if it helps to add this feature in a future release.
Note that it is always the contents of the directory that is synced, not the directory so when source:path is a directory, it’s the contents of source:path that are copied, not the directory name and contents.
And if you want to copy the directory, there is an easy work around - just repeat the directory name on the end like I did above.
I deliberately didn't do the trailing / thing that rsync does as it is very easy to make a mistake with it, and it has been a source of data loss and confusion for beginners. When this last came up in #383 I wrote this:
I'm of the opinion that rsync's way of doing it, while clever, is extremely error prone and a mis-feature.
Then you just deleted all the files in your backup and re-uploaded them :-(
I made rclone so that the trailing slash is irrelevant like it is in the rest of the unix world and it always refers to the directory contents.
I did write this in the docs to address this point for new users
If you are familiar with rsync, rclone always works as if you had
written a trailing / - meaning "copy the contents of this directory".
This applies to all commands and whether you are talking about the
source or destination.
I think, practically speaking, it is too late to change it, even if I wanted to :-(
Reacted by Victor Escorcia, Tarık Kavaz, Francesc Rosas, NotExist, Simon Li, Ivan Andreev, Krista DeStasio, Sahib Bhai, Sergey Zozulya, d-air1 and 4 more
I think, practically speaking, it is too late to change it, even if I wanted to :-(
You could add a flag that will turn on rsync's behaviour so that brave users can make aliases. Everyone would be happy. ;-) Or perhaps just a (single-letter) flag that will make rclone copy sources into a traget directory. Or both. I'm more in favour of the first as I'm used to rsync syntax and I'd just make an alias for rclone with the flag.
Reacted by zuzzurro, Long, Gui Ambros and Bas van den Wollenberg
A bash function based on the above that works for me. Replace YourDestinationDrive with where you want to copyto. rclone_folder () { rclone copyto "${1// /\\ }" YourDestinationDrive:"${1// /\\ }" }
Please update your reply that's not an appropriate manner to ask questions or request features. Impolite and harsh feedback damages the community.
If your shell is bash, you could use bash-scripting. file=very_long_path_from_autocompletion; rclone copy $file TestDrive:$file. There are two commands there. The first command (before ;) defines a variable, and the second command spawns a call to rclone.
If you have multiple files, I usually create a small script to dump a txt-file with the path and use --files-from list-with-files.txt. The documentation explains this clearly.
Hi there @ncw. Chiming in to say that I also believe that a flag to enable rsync's behaviour (or one that works like -R for cp, even better) would be quite useful. I can open a new issue if you want . Hope you're doing well. :)
Edit: Found a comment by you stating you plan to implement cp and mv commands that follow the default unix behavior in the future. I think that'd be perfect and hope it's still in the picture. :)
@dausruddin@castanley
Your +1 comments hardly help the project, just spam the watchers mailboxes.
Please use the 👍 counter on the issue heading.
Thank you.
The common idea here is that rclone copy and rclone sync diverge from usual cp and rsync in syntax and semantics resulting in degraded UX.
It's pretty clear as rclone unlike cp was initially created as a cloud tool, and has been optimized right for network environment.
We cannot change syntax of existing commands as it would break compatibility with existing rclone wrappers and scripts. Instead, we'll add new subcommands with homelike syntax.
Unfortunately this issue has become a mix of unconnected requests/rants. It's really hard to track and implement this way.
Activity
Stele77 commentedon Mar 11, 2017
I am having the same problem AFAIK (I am a noob on Rclone), Rclone doesnt copy empty folders. See this issue and please push it too:
#100
ncw commentedon Mar 13, 2017
@orlandordiaz rclone copies directory to directory, so to do what you want use
orlandodiaz commentedon Mar 15, 2017
Please read my post again. I tried that command and it only copies the contents and subdirs without including the root folder itself. Not sure if this is a bug or if that's the intended behavior. If so, any way to work around it? Including folder should be the default IMO since that 'the default behavior of the cp command. If I wanted to copy only the contents I would have done srcdir/ remote:dest with the forward slash at the end.
ncw commentedon Mar 16, 2017
rclone doesn't work like cp it works like rsync which syncs directories to directories.
So you need to name the remote directory in the copy, so
copy dir1 remote:src/dir1if I've understood your example correctly.emilfihlman commentedon Apr 13, 2017
rclone should definitely copy exactly what we tell it, not just the contents, so dir for whole dir and dir/ for just the contents. The behaviour should be amended.
orlandodiaz commentedon May 12, 2017
ncw doing
copy dir1 remote:src/dir1still copies the contents and doesnt preserve foldername.Doing
copy dir1 remote:src/newDirName/only works for a specified dirname an when the dir exists on google drive.Any chance you could implement this simple feature? It's just the case that preserving the directory name is extremely important in my case and im sure others might find that helpful at some point
[-]Copy entire directory structure, not just its contents[/-][+]Copy entire directory structure, not just the contents[/+]RobbieL811 commentedon May 16, 2017
I'm having this issue. I'm experienced with rsync, and the behavior is not the same. With rsync, if you remove the tailing / from the source path, it tells rclone to copy also the source directory instead of just it's contents. @ncw, is there any way that we can make rclone behave the same in that regard? Would be nice to be able to copy directories without having to name them in the dest path. By the way, I'm not criticizing. Just thinking out loud. Thanks for the great tool!!!
SimonLefisch commentedon May 31, 2017
+1 for this. Rclone is a great tool, but it should have a basic function like this implemented. @ncw, would be great to have this feature. Thanks for your hard work on this tool. I will be donating if it helps to add this feature in a future release.
streaps commentedon Aug 9, 2017
I would call this behaviour a usability bug. It makes no sense at all... Does anyone know an alternative to rclone that supports google team drives?
ncw commentedon Aug 9, 2017
Did you try the copyto command?
streaps commentedon Aug 9, 2017
rclone suggest that there is no difference between the two commands:
copy Copy files from source to dest, skipping already copied
copyto Copy files from source to dest, skipping already copied
rclone copyto --help
"If the source is a directory then it acts exactly like the copy command."
This doesn't seem to address the issue, if I understand it correctly.
ncw commentedon Aug 10, 2017
@streaps I'm not sure I understand the issue
Here is my fix for @orlandordiaz original issue (done on local disk)
or done on a remote if you prefer
Which seems to solve the original problem.
This is documented in the copy command docs:
And if you want to copy the directory, there is an easy work around - just repeat the directory name on the end like I did above.
I deliberately didn't do the trailing
/thing that rsync does as it is very easy to make a mistake with it, and it has been a source of data loss and confusion for beginners. When this last came up in #383 I wrote this:I'm of the opinion that rsync's way of doing it, while clever, is extremely error prone and a mis-feature.
If you type
Then one say with a bit of command line completion help, type
Then you just deleted all the files in your backup and re-uploaded them :-(
I made rclone so that the trailing slash is irrelevant like it is in the rest of the unix world and it always refers to the directory contents.
I did write this in the docs to address this point for new users
I think, practically speaking, it is too late to change it, even if I wanted to :-(
woky commentedon Nov 26, 2017
You could add a flag that will turn on rsync's behaviour so that brave users can make aliases. Everyone would be happy. ;-) Or perhaps just a (single-letter) flag that will make rclone copy sources into a traget directory. Or both. I'm more in favour of the first as I'm used to rsync syntax and I'd just make an alias for rclone with the flag.
ncw commentedon Nov 28, 2017
@woky nice idea. Please make a new issue on github with this idea in and have a go at specifying what the flag should do.
4 remaining items
escorciav commentedon Apr 8, 2019
The solution here worked.
Please note that we also need to write
dir1in the remote part,TestDrive. I guess that's what the issue plan to address.Thanks for making this public.
SemiQuant commentedon Apr 17, 2019
A bash function based on the above that works for me. Replace YourDestinationDrive with where you want to copyto.
rclone_folder () { rclone copyto "${1// /\\ }" YourDestinationDrive:"${1// /\\ }" }escorciav commentedon Jun 8, 2019
Please update your reply that's not an appropriate manner to ask questions or request features. Impolite and harsh feedback damages the community.
If your shell is bash, you could use bash-scripting.
file=very_long_path_from_autocompletion; rclone copy $file TestDrive:$file. There are two commands there. The first command (before;) defines a variable, and the second command spawns a call torclone.If you have multiple files, I usually create a small script to dump a txt-file with the path and use
--files-from list-with-files.txt. The documentation explains this clearly.streaps commentedon Jun 8, 2019
but this is not really user friendly and does not work for windows.
piratetub commentedon Nov 29, 2019
Hi there @ncw. Chiming in to say that I also believe that a flag to enable rsync's behaviour (or one that works like
-Rforcp, even better) would be quite useful. I can open a new issue if you want . Hope you're doing well. :)Edit: Found a comment by you stating you plan to implement
cpandmvcommands that follow the default unix behavior in the future. I think that'd be perfect and hope it's still in the picture. :)animosity022 commentedon May 10, 2020
@orlandodiaz - it looks like your initial issue has been solved. is this good to close out?
dausruddin commentedon Sep 18, 2020
Would be great to see this implemented.
castanley commentedon Nov 7, 2020
+1 on getting this implemented :D 👍
ivandeex commentedon Nov 16, 2020
@dausruddin @castanley
Your
+1comments hardly help the project, just spam the watchers mailboxes.Please use the 👍 counter on the issue heading.
Thank you.
ivandeex commentedon Nov 16, 2020
@orlandodiaz looks like you are no longer interested in this request, since May 2020.
ivandeex commentedon Nov 16, 2020
The common idea here is that
rclone copyandrclone syncdiverge from usualcpandrsyncin syntax and semantics resulting in degraded UX.It's pretty clear as rclone unlike
cpwas initially created as a cloud tool, and has been optimized right for network environment.We cannot change syntax of existing commands as it would break compatibility with existing rclone wrappers and scripts. Instead, we'll add new subcommands with homelike syntax.
Unfortunately this issue has become a mix of unconnected requests/rants. It's really hard to track and implement this way.
Closing in favor of #4776 and #4777