0

I need to search for files and directories that are spread throughout different parts of a database, then copy them to folders that will be named based on the file contents. Many of the files/directories have a 10-digit number that will be the name of the folder they will be copied to.

My thoughts are that I will:

  1. Create a list of the unique 10-digit numbers (already done).
  2. Recursively perform a search for each of those numbers in the list of file paths (I already created the list of file paths).
  3. Recursively name the folders I will be copying the files/directories to (titled with those 10-digit numbers) as I copy them to the new folders.

Don't care about metadata copying over. The file paths will be new (nothing overwritten, and I have necessary access/permissions).

I'm thinking about doing it like what is shown here: Copy files using python with complete folder structure

But I'm confused as to how I would set up the code so I could iterate through my list of (windows) file paths, my list of folder names (10-digit numbers), and another list of associated file paths for each folder (that list is still not made, might have to be a separate list for each folder).

Luckily, most of the file paths have that 10-digit identifier, and I've already got a searchable list.

So, how would I recursively feed those 3+ lists into the code to copy the files over? Would it make more sense to feed it into a pd.dataframe?

Code from the link below that I'm considering using, but open to suggestions. I'm not sure this will accept a list(s). The files and sub-directories will be moving into a new folder within the same directory (pictured).

filePath=["D:\\", "C:\\Users"]
# ext=['mkv','docx','doc','pdf','mp4','zip',]
fileExt=["**\*.docx","**\*.doc","**\*.pdf"]
fileList={}
for each_drive in filePath:
    fileList[each_drive]={}
    for each_type in fileExt:
        fileList[each_drive][each_type]=list(pathlib.Path(each_drive).glob(each_type))

file1 = open('test.txt', 'w')
for each in fileList.values():
    for each2 in each.values():
        for entry in each2:
            print(entry)
            file1.writelines(str(str(entry)+ "\n"))

enter image description here

0 Answers0