1

I have a directory/folder which contains multiple files and folders(or you can say sub-folders). I want to copy one folder from the directory and paste it inside another directory/folder. I tried copytree and copy_tree which is available in shutil and dist_utils respectively which copy's entire content of the folder but I don't know how to use it in my scenario. I don't want to copy files executing commands using python. I am sharing example folder structure

#source folder

test_directory:
│   sample.txt
│
├───source
│       test.txt
│
├───source2
└───source3
        sample3.txt


#destination folder

destination_directory

│   sample.txt
│
└───dest

so assume I want to move folder name "source" from test_directory folder to destination_directory folder.

so after copying folder to destination folder my folder structure should look like

destination_directory
│   sample.txt
│
├───dest
└───source
        test.txt
amol rane
  • 325
  • 1
  • 13
  • 2
    Does this answer your question? [How do I copy an entire directory of files into an existing directory using Python?](https://stackoverflow.com/questions/1868714/how-do-i-copy-an-entire-directory-of-files-into-an-existing-directory-using-pyth) – Gal Jul 17 '20 at 11:41
  • @Gal as I mentioned in my question I have already tried it. the problem with copytree is it copy entire files within the mentioned directory but I want to copy only a particular folder – amol rane Jul 17 '20 at 11:51
  • Why not use bash? – bigbounty Jul 17 '20 at 11:56
  • If you tried `copytree` and it didn't work for you, did you try: `shutil.copytree('/test_directory/source', '/destination_directory/source')`? – Booboo Jul 17 '20 at 12:09
  • I know shutil.copytree creates folder and then copy's the content but it will not work if I try to copy content if folder is already there, right? – amol rane Jul 17 '20 at 12:14

0 Answers0