fileToSend1="C:/remo.txt"          #Provide the file path here

import os,re,sys
import _winreg,difflib
import shutil

def alert(arg):
    sys.stderr.write("%d%d%d" % (arg, arg, arg))


fileToSend2=os.path.join(os.environ['ProgramData'],'new_file.txt')

def compare():
    file1=fileToSend1
    file2=fileToSend2
    c=0
    f=open(file1,'r')  
    f1=open(file2,'r') 
    str1=f.read()
    str2=f1.read()
    str1=str1.splitlines(1) 
    str2=str2.splitlines(1) 
    d=difflib.Differ()     
    diff=list(d.compare(str2,str1))
    diff1="\n".join(diff)
    diff2=re.findall("- (.*)",diff1)
    diff3=re.findall("\+ (.*)",diff1)
    if diff2:
        print diff2
        c=1
    if diff3:
        print diff3
        c=1
    return c

if not os.path.exists(fileToSend1):
    print "The specified file is not available"
    s=2

else:
    if not os.path.exists(fileToSend2):
        shutil.copy(fileToSend1,fileToSend2)
        s=compare()

    else:
        s=compare()
    
if s==1:
    print 'YES - (Changes made in the file )'+fileToSend1
    alert(1)
    shutil.copy(fileToSend2,fileToSend1)
    print 'Replaced the file with a file that contains the correct content successfully'
elif s==2:
    alert(0)
else:
    print "NO - (No Changes have made in the file )"+fileToSend1
    alert(0)
    
    
