简体   繁体   中英

Copy files from subfolders into same name of subfolders at other directory

I need python script, which should be capable for copying files from different subfolders into new directory and this new directory should contain same subfolders. I am unable to create this sub_folders at destination during run time. can anybody help me.

for example: source_folder: sub_folder1: test1.txt image1.jpg sub_folder2: test2.txt image2.jpg sub_folder3: test3.txt image3.jpg

destination_folder: sub_folder1: test1.txt sub_folder1: image1.jpg sub_folder2: test2.txt sub_folder2: image2.jpg sub_folder3: test3.txt sub_folder3: image3.jpg

Try to use os.makedirs() (need to import os ) to create directory runtime. Pls. check the documentation and some examples.

Also, refer using shutil https://www.geeksforgeeks.org/copy-a-directory-recursively-using-python-with-examples/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM