'Python - Compare filenames in lists

I have code which check if files contents are the same. Files have the same filename in both folders. For example:

folder JSON1/test1.txt
folder JSON2/test1.txt

For a single file this works, but I would like to apply it to a list of files. So in the JSON1 folder I will have:

JSON1 / test.txt
JSON1 / second.txt
JSON1 / result.txt

And in the JSON2 folder I will have the same file list. Can you help how to change it to handle multiple files?

import os
import sys

filenameODS = "C:/Users/adm/Json1/" + sys.argv[1] + ".txt"
filenameDWH = "C:/Users/adm/Json2/" + sys.argv[1] + ".txt"

file1contents = set(open(filenameODS).readlines())
file2contents = set(open(filenameDWH).readlines())

if file1contents == file2contents:
    print("Files are the same!")
else:
    print("In file2, not file1:\n")
    for diffLine in file2contents - file1contents:
        print ("\t", diffLine)
    print ("\nIn file1, not file2:\n")
    for diffLine in file1contents - file2contents:
        print ("\t", diffLine)
    with open('C:/Users/adm/Json3/'+ sys.argv[1] + '.txt', 'w') as f:
        f.write(diffLine)
        f.close()



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source