2

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?

Markus
  • 3,155
  • 2
  • 23
  • 33
  • If you make sure that `bar` as `destination` param in `Copy Directory ./foo bar/` doesn't exist, there will be no `foo` created inside `bar`. Perhaps that's one solution (not a very nice one). – pavelsaman Jul 20 '20 at 12:13
  • @pavelsaman Unfortunately that is no option, as ``bar`` is some rather largish directory containing lots of files and subdirectories. I just need to copy over everything contained in ``foo``. – Markus Jul 20 '20 at 14:05
  • 2
    Grab some of the answers here that suites you the most, create a python file with the function and import it in your test; https://stackoverflow.com/questions/1994488/copy-file-or-directories-recursively-in-python/1994840. HTH – Todor Minakov Jul 20 '20 at 17:50

1 Answers1

1

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
Markus
  • 3,155
  • 2
  • 23
  • 33