Skip to content

Copy entire directory structure, not just the contents #1228

Closed

Description

@orlandodiaz

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

Activity

  1. Stele77 commented on Mar 11, 2017

    @Stele77

    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

  2. ncw commented on Mar 13, 2017

    @ncw
    Member

    @orlandordiaz rclone copies directory to directory, so to do what you want use

    rclone copy dir1 src:dir1
    
  3. orlandodiaz commented on Mar 15, 2017

    @orlandodiaz
    Author

    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.

  4. ncw commented on Mar 16, 2017

    @ncw
    Member

    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/dir1 if I've understood your example correctly.

  5. emilfihlman commented on Apr 13, 2017

    @emilfihlman

    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.

  6. orlandodiaz commented on May 12, 2017

    @orlandodiaz
    Author

    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

  7. changed the title [-]Copy entire directory structure, not just its contents[/-] [+]Copy entire directory structure, not just the contents[/+] on May 12, 2017
  8. RobbieL811 commented on May 16, 2017

    @RobbieL811

    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!!!

  9. SimonLefisch commented on May 31, 2017

    @SimonLefisch

    +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.

  10. streaps commented on Aug 9, 2017

    @streaps

    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?

  11. ncw commented on Aug 9, 2017

    @ncw
    Member

    Did you try the copyto command?

  12. streaps commented on Aug 9, 2017

    @streaps

    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.

  13. ncw commented on Aug 10, 2017

    @ncw
    Member

    @streaps I'm not sure I understand the issue

    Here is my fix for @orlandordiaz original issue (done on local disk)

    $ mkdir dir1
    $ touch dir1/file1
    $ touch dir1/file2
    $ mkdir src
    $ tree dir1
    dir1
    ├── file1
    └── file2
    
    0 directories, 2 files
    $ rclone copy dir1 src/dir1
    $ tree src
    src
    └── dir1
        ├── file1
        └── file2
    
    1 directories, 2 files
    

    or done on a remote if you prefer

    ncw@dogger:/tmp/test$ rclone copy dir1 TestDrive:src/dir1
    ncw@dogger:/tmp/test$ rclone tree TestDrive:src
    /
    └── dir1
        ├── file1
        └── file2
    
    1 directories, 2 files
    

    Which seems to solve the original problem.

    This is documented in the copy command docs:

    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.

    If you type

    rsync -av --delete /path/to/my/files dest:/path/to/backup
    

    Then one say with a bit of command line completion help, type

    rsync -av --delete /path/to/my/files/ dest:/path/to/backup
    

    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 :-(

  14. woky commented on Nov 26, 2017

    @woky

    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.

  15. ncw commented on Nov 28, 2017

    @ncw
    Member

    @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.

  16. 4 remaining items

  17. escorciav commented on Apr 8, 2019

    @escorciav

    The solution here worked.

    ncw@dogger:/tmp/test$ rclone copy dir1 TestDrive:src/dir1
    ncw@dogger:/tmp/test$ rclone tree TestDrive:src
    /
    └── dir1
        ├── file1
        └── file2
    
    1 directories, 2 files
    

    Please note that we also need to write dir1 in the remote part, TestDrive. I guess that's what the issue plan to address.

    Thanks for making this public.

  18. SemiQuant commented on Apr 17, 2019

    @SemiQuant

    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// /\\ }" }

  19. escorciav commented on Jun 8, 2019

    @escorciav

    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.

  20. streaps commented on Jun 8, 2019

    @streaps

    but this is not really user friendly and does not work for windows.

  21. piratetub commented on Nov 29, 2019

    @piratetub

    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. :)

  22. animosity022 commented on May 10, 2020

    @animosity022
    Contributor

    @orlandodiaz - it looks like your initial issue has been solved. is this good to close out?

  23. dausruddin commented on Sep 18, 2020

    @dausruddin
    Contributor

    Would be great to see this implemented.

  24. castanley commented on Nov 7, 2020

    @castanley

    +1 on getting this implemented :D 👍

  25. ivandeex commented on Nov 16, 2020

    @ivandeex
    Member

    @dausruddin @castanley
    Your +1 comments hardly help the project, just spam the watchers mailboxes.
    Please use the 👍 counter on the issue heading.
    Thank you.

  26. ivandeex commented on Nov 16, 2020

    @ivandeex
    Member

    @orlandodiaz looks like you are no longer interested in this request, since May 2020.

  27. ivandeex commented on Nov 16, 2020

    @ivandeex
    Member

    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.

    Closing in favor of #4776 and #4777

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions