I'm new to using Spyder 2.3.0 and Python 3.4.1
I have a directory structure with sub directories.
Unlike other examples on the web I want to select multiple file types and copy the directory structure across. I have tried below and it works but it takes only one file type at a time and “<code>copytree’s” across (it’s going to be very slow).
Is there a way or different way to streamline this to make it faster?
What I was thinking I wanted to do was:
Make a comprehensive list of file types and locations (walking through directory structure)
For example ending with
fileExt = [".txt", ".doc", ".docx", ".xls",".xlsx", ".ppt", ".pptx", ".m", ".xmcd", ".pdf " ]
Then with that list simply “<code>shutil.copytree”</p>
Any advice greatly appreciated.
srcDir = 'c:/a/src/dir/'
dirName = 'c:/a/dest/dir/'
import os
import shutil
##################################################################################
dstDir = os.path.abspath(dirName)
def ignore_list(path, files):
filesToIgnore = []
for fileName in files:
fullFileName = os.path.join(os.path.normpath(path), fileName)
if not os.path.isdir(fullFileName) and not fileName.endswith('.txt') :
filesToIgnore.append(fileName)
return filesToIgnore
# start of script
shutil.copytree(srcDir, dstDir, ignore=ignore_list)
####################################################################################################################################################################
dstDir = os.path.abspath(dirName)
def ignore_list(path, files):
filesToIgnore = []
for fileName in files:
fullFileName = os.path.join(os.path.normpath(path), fileName)
if not os.path.isdir(fullFileName) and not fileName.endswith('.docx') :
filesToIgnore.append(fileName)
return filesToIgnore
# start of script
shutil.copytree(srcDir, dstDir, ignore=ignore_list)
####################################################
Copy and paste changing “endswith('.docx') :”</p>