Let us assume there is a folder X and then a folder Y, I would like to go to both "folder X" and "folder Y" and compare the file names 1 by 1 using python language. How would I do that? I tried using the following code:
for f in dir_list: # iterates through the folder X and look for files in Folder X
for h in dir_list2: # iterates through the folder Y and look for files in Folder Y
name = os.path.basename(f) # returns every file names
name2= os.path.basename(h)
if (name==name2):
print("its a match")
else:
print("nope, does not match") # My all files match,
# but I got output saying they do not match.
# Not sure why would it say not a match even though they are all same files in Folder X and Folder Y
# Can someone suggest a better way to compare files names from 2 folders?
The above code prints the name of every file in folders and results some files as "Not a match", even though they are same files. Instead of printing every file, how do I make it show the name of files that do not match and the ones that do match?