The script below was developed to transfer only selected files from one directory to another. The selected files are given as a list in a txt file.
This script was used in applications were we required a sub set of retinal images contained within a large directories of images. It is not practical to open the directory and browse images due to the number of images contained in the directory. Manual transfer of selected images is not possible.
The setup of this system of a large number images contained in one directory is not best practice, but has been inherited from legacy systems.
import csv import os from shutil import copyfile def copyFiles(inputDirectoryName,outputDirectoryName, filterCriteriaFileName): #input file reader infile = open(filterCriteriaFileName, "r") read = csv.reader(infile) for row in read: inputDirectoryPath = os.path.abspath( os.path.join(inputDirectoryName, row) ) outputDirectoryPath = os.path.abspath( os.path.join(outputDirectoryName, row) ) try: copyfile(inputDirectoryPath, outputDirectoryPath) except: print("No Such File "+row) #/endfor #/copyFiles() copyFiles('InputFolder','OutputFolder','SelectedFileNames.csv')