Skip to main content
2 of 9
added 70 characters in body
Jamal
  • 34.9k
  • 13
  • 133
  • 237

How to copy a directory structure to another, but only copying specific files in python 2.7?

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('pyc') and not fileName.endswith('ui') and not fileName.endswith('txt') and not fileName == '__main__.py' and not fileName == 'dcppo.bat':

            filesToIgnore.append(fileName)

    return filesToIgnore

# Start of script

shutil.copytree(srcDir, dstDir, ignore=ignore_list)

I want to change the if line containing files to copy. Here I have to give the filenames separately, but I want to change it (like it should take filenames from a list containing all file names).

How can I do this?

Patrick
  • 369
  • 2
  • 3
  • 11