I have two directories in which I have text files with same matching file names. I need to compare same name texts files respectively and write out the unmatched words in csv with respective file name.
Folder1:
file1.txt file2.txt
Folder2:
file1.txt file2.txt
Here i need findall unmatched words from comparing the two. I have something like below
stat="files, unmatch_words\n"
pack=os.list('./Folder1/')
for file in pack:
package=open('./Folder1/' + file, 'r').read()
grep=open("./Folder2/" + file,'r').read()
output= re.findall(r'(\w+)',grep)
rex=(set(output))
stat += file.replace('.txt', '') + ',"'
for sem in rex:
if sem not in package:
stat += sem + '\n'
stat += '","'
stat += '"' + '\n'
f=open('file.csv', 'w')
f.write(stat)
This combines all files in Folder2 (i.e rex) in to one and comparing it with files in Folder1.
I want to unmatch words from Folder1 -> file1.txt with Folder2 -> file1.txt like wise Folder1 -> file2.txt with Folder2 -> file2.txt
Can anyone please suggest any update on this. Thanks