I have a library at hand to compare two files, getting the diff. The library does not play a role in the question.
I can compare two files at one time by inputting the file path of the files, but since I have several files that need to be compared, I'm thinking of automating this, without the need to input the file path each time.
For example:
I want to compare file1 of folder 1 with file1 of folder 2 and so on, and all in one go, using the name as the matching point.
How can I do this?
From your comment above, it seems like you already have the library to make the file diff and just want a way to walk a directory tree. You can look into os.listdir
and just loop through all of the files in folder1 and then use the name of the files to determine what the name of the second file is in folder2.
Going off of your example, maybe something like this.
for file_name in os.listdir('./folder1'):
file_1_path = os.path.join('./folder1', file_name)
name, ext = os.path.splitext(file_name)
file_2_path = os.path.join('./folder2', name + name[-1] + ext)
f1 = open(file_1_path, 'r')
f2 = open(file_2_path, 'r')
( diff logic here )