I have a large folder with lots of subfolders, each of which contains one to several files. I'd like to move some of these files based on their filename. I have a list containing the filenames of the files I want to move, so basically I would like to check for every file in the mither directory if it's name's on the list and if so - move it to the new directory.
I wrote the following script, but unfortunately it doesn't work. Does anyone have an idea how to fix it, or a better suggestion for a script that would perform the desired function?
import os
import shutil
curr_fold = "/Users/ruthersh/Alice/Bacterial_seqs/FAA"
dest = "/Users/ruthersh/Alice/Bacterial_seqs/Plasmids"
for (dirname, dirs, files) in os.walk(curr_fold):
for filename in files:
if (filename[:9]) in NCS:
src = os.path.realpath(filename)
shutil.move(src, dest)