# Example usage: # > python "C:\Users\jborthen\Desktop\Desktop Files\Python\Python Scripts\compareFiles.py" # > Input path to File1: 'C:\Users\jborthen\Desktop\SDWE\SDWE\UPDAT_Files\Systems\TBEC_add.upd' # > Input path to File2: 'C:\Users\jborthen\Desktop\SDWE\SDWE\UPDAT_Files\PECPs\pecp024.upd' import os os.chdir('C:\Users\jborthen\Desktop\Desktop Files\Python\Python Scripts') File1=input("\nInput path to File1: ") File2=input("\nInput path to File2: ") with open(File1, 'r') as file1: with open(File2, 'r') as file2: same1to2 = set(file1).difference(file2) same1to2.discard('\n') with open(File2, 'r') as file2: with open(File1, 'r') as file1: same2to1 = set(file2).difference(file1) same2to1.discard('\n') with open('File_Comparison.txt', 'w') as file_out: file_out.write(" ==================================================================================\n\n") file_out.write(" File1: " + File1 +"\n") file_out.write(" File2: " + File2 + "\n\n") file_out.write(" ==================================================================================\n\n") file_out.write("Items in File1 but not in File2:\n\n") for line1 in same1to2: if not line1.startswith("#"): file_out.write(" " + line1) file_out.write("\n\nItems in File2 but not in File1:\n\n") for line2 in same2to1: if not line2.startswith("#"): file_out.write(" " + line2)