Skip to content
Advertisement

how do I copy over a few folders from one directory into another folder in Linux using python

I’m trying to copy over a bunch of folders, read from a txt file into another folder . How do I do this? I’m using python in Linux

e.g this txt file has the following folder names

JavaScript

and I want to copy these folders and their contents to a folder called duplicate-folder

How do I do this? I tried the following code but it gave an error because I think it’s only for files, not folders :)

JavaScript

Advertisement

Answer

use shutil.copytree(src, dest, ...) (https://docs.python.org/3/library/shutil.html#shutil.copytree) for directories (also copies subfiles and -directories. And also don’t forget to give it the full path for file and dest (don’t know which value your temp3 var holds). If you don’t give it a full path, but only a filename, it will search in the current working directory.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement