Copy entire directory with python

0
Hello, I would like to copy an entire directory using python, since I have a site database ready and every time I create a new project I have to keep moving the files to a new folder. I would like to do this, without moving those files but rather giving a ctrl-c in them and ctrl-v in the target folder.

Would it be possible to do this with python?

    
asked by anonymous 26.03.2018 / 16:35

1 answer

1

You can use the shutil library

Please note that it has a warning about the inability to copy metadata, you may find other problems depending on your OS.

The best solution would be to write the Bash copy script in linux or shell (cmd) on windows and call the routine from within Python using subprocess . It can be as simple as:

import subprocess
in_dir = #"pasta a copiar"
out_dir = #"local de destino"
rotina = ["cp",in_dir,out_dir] # exemplo usando Bash
processo = subprocess.run(rotina)
    
26.03.2018 / 22:39