Python: copy and paste files based on paths in two csvs
Question: I have two csv files, one with a list of paths for source files, the second, a
list of paths for where to copy the files to. Both files have the same number
of elements and each source file is only copied once.

How would I load the .csv files (Pandas? Numpy? csv.reader?), and how would I
copy all of the items in the best possible way? I am able to get the following
to work if `src` and `dest` each refer to one path.

    
    
    import pandas as pd
    srcdf = pd.read_csv('src.csv')
    destdf = pd.read_csv('dest.csv')
    
    from shutil import copyfile
    copyfile(src,dest)
    

There are no headers or columns in my files. It's just a vector of comma-
separated values. The comma-separated values in my `src` csv file are look
like:

    
    
    /Users/johndoe/Downloads/50.jpg,
    /Users/johndoe/Downloads/51.jpg,
    

In my `dest` csv file are like:

    
    
    /Users/johndoe/Downloads/newFolder/50.jpg,       
    /Users/johndoe/Downloads/newFolder/51.jpg,
    


Answer: Assuming your CSV is just a list of paths with a single path on each row, you
could do something like this:

    
    
    import csv
    from shutil import copyfile
    
    def load_paths(filename):
        pathdict = {}
        with open(filename) as csvfile:
            filereader = csv.reader(csvfile, delimiter=' ')
            a = 0
            for row in filereader:
                pathdict[a] = ''.join(row)
                a += 1
            csvfile.close()
            return pathdict
    
    srcpaths = load_paths('srcfile.csv')
    dstpaths = load_paths('dstfile.csv')
    
    for a in range(len(srcpaths)):
        copyfile(srcpaths[a],dstpaths[a])
    

