Click here to Skip to main content
15,867,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am comparing all files in two directories, if comparison is greater than 90% so i continue the outer loop and i want to remove the file in the second directory that was matched so that the second file in the first directory doesn't compare with the file that's already matched.


I know i cannot change the iteration once it's in action that's why its returning me file not found error i dont want to use try except blocks. Any ideas appreciated

What I have tried:

Here's what i've tried:

for i for i in sorted_files:
    for j in sorted_github_files:
            #pdb.set_trace()
            with open(f'./files/{i}') as f1:
                try:
                    text1 = f1.read()
                except:
                    pass
            with open(f'./github_files/{j}') as f2:
                try:
                    text2 = f2.read()
                except:
                    pass
            m = SequenceMatcher(None, text1, text2)
            print("file1:", i, "file2:", j)
            if m.ratio() > 0.90:
                 os.remove(f'./github_files/{j}')
                 break
Posted
Comments
Richard MacCutchan 28-Oct-21 4:22am    
Do the files have the same names in both locations?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900