Reputation: 21
I am comparing filenames in a directory with a list of filenames I generated from an excel specific sheet then moving the files with matching filenames to a new folder called 'moved_files'.Why is my if statement ignored and no files are moved when the code runs and prints "done" at the end?
I have used print statements before the last if statement to see the pdb_filename and filename_gen and some of the filename_gen do match with pdb_filename. The print statement doesn't print although there are files with .pdb at the end in the directory.
Here is the code
for filename_gen in list_filename_gen:
for pdb_filename in os.listdir(directory):
if pdb_filename.endswith(".pdb"):
print(pdb_filename)
if print filename_gen ==print pdb_filename :
shutil.move(os.path.join(directory, pdb_filename),'/Users/fififoufa/Desktop/files_moved/%s' % (pdb_filename))
print("done")
I expect to see files moved when the names exactly match e.g files\xTMEM16A_dimer_OPM_PI4P\500_4.pdb and files\xTMEM16A_dimer_OPM_PI4P\500_4.pdb
Upvotes: 0
Views: 52
Reputation: 9
You're not exactly comparing the two file names, you're instead comparing two print calls which would return True. if filename_gen == pdb_filename:
Upvotes: 1