Recursively copy the *contents* of a directory

Viewed 370

Using any of the standard Robot libraries, is it possible to recursively copy the contents of a directory to an existing destination directory?

Basically, I'm looking for the equivalent of the following shell command: cp -r foo/. bar (note the trailing dot)

I tried Copy Directory but this creates a directory foo inside bar (as documented) and it doesn't stop doing that even when supplying the trailing dot. Copy Files chokes when it encounters a directory.

Is there anything I overlooked? Or do I need to just call cp -r myself?

1 Answers

As I only need this to work on Linux, I ended up implementing a custom keyword calling cp -r. If this is ever needed cross-platform, then I'll follow the suggestions to directly implement it in Python.

Copy Directory Contents
   [Documentation]   Recursively copies the contents of the source directory into the destination.
   [Arguments]   ${source}   ${destination}
   Directory Should Exist   ${source}
   Directory Should Exist   ${destination}
   ${result} =   Run Process   cp   -r   ${source}/.   ${destination}/
   Should Be Equal As Integers   ${result.rc}   0
Related