How to copy all the files in certain Directory and recreate the directory structure dynamically using python -
i want move files of type existing directory structure new dynamic directory structure.for e.g: if file is
c://users//desktop//635289512-251.txt
i need place file in
c://users//desktop//635_users//2895_access//635289512-251.txt
should copy each , everyfile , paste them in directory or can zip them , unzip them dynamically? using below code create directory. please me if there better way of doing this.
thank you help.
src = "folder1/folder2/file1" dst = "folder3"+src dstfolder = os.path.dirname(dst) if not os.path.exists(dstfolder): os.makedirs(dstfolder) shutil.copy(src,dst)
use shutil.copytree
copy entire directory new location.
import shutil src = "folder1/folder2/file1" dst = "folder3"+src dstfolder = os.path.dirname(dst) shutil.copytree(src,dstfolder)
Comments
Post a Comment