Alan,<br> <br> Thanks for that. I had the wrong file names, now it works, in case anyone is interested here is the code. I use it because at work I need to change different versions of sqlnet.ora :-<br> <br> def compare_files(file_name1, file_name2):<br> x = filecmp.cmp (file_name1, file_name2)<br> print x<br> return x<br> <br> def change_files(file_1, file_2, cwd):<br> yesorno = raw_input("Do you want them to be the same Y or N ")<br> #file_1 = cwd+file_1<br> #file_2 = cwd+file_2<br> yesorno = string.upper(yesorno)<br> if yesorno == 'Y':<br> try:<br> os.remove(file_2)<br> print "removed file 2"<br>
except:<br> print "could not remove file"<br> <br> try:<br> shutil.copy(file_1, file_2)<br> print "the copy part thinks it worked"<br> except:<br> print "it did not work"<br> else:<br> print "ok not changing anything"<br> def did_it_work(file_1, file_2):<br> #this is to debug the copy,only run if you are having problems<br> afterchange = compare_files(file_1,file_2 )<br> if afterchange == True:<br>
print "the copy went fine"<br> else:<br> print "problem with the copy" + str(afterchange)<br> #main<br> import shutil<br> import string<br> import filecmp<br> import os<br> a = os.getcwd()<br> print a<br> file1 = "SQLNETpersonal.ORA"<br> file2 = "SQLNETclients.ORA"<br> file3 = "SQLNET.ORA"<br> x = compare_files(file1,file3 )<br> if x == False:<br> print file1 + " and "+ file3+ " are different"<br> #print "test1 and test3 are different"<br> change_files(file1, file3,a)<br> #did_it_work(file1, file3)<br> else:<br> x = compare_files(file2,file3 )<br> if x == False:<br> print file2 + " and " +file3 +" are different"<br> change_files(file2, file3,a)<br>
#did_it_work(file2, file3)<br> print "program finished"<br> <br> <br><br><b><i>Alan Gauld <alan.gauld@freenet.co.uk></i></b> wrote:<blockquote class="replbq" style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"> > The only problem is that despite the fact that as the same user,<br>> I can manually change these files (so I must have the right file <br>> permissions ?)<br><br>Can you do it from within python at the >>> prompt<br><br>Use os.getcwd() to find out where you are<br>Use os.chdir() to navigate<br>Use os.listdir() to list the folder contents<br>and use shutil.copy() to copy the files.<br><br>Doing it manually from inside the >>> prompt should<br>show up any problems. You can even try the filecomp<br>call from in there too... >>> is a powerful tool.<br><br>HTH,<br><br>Alan G<br>Author of the learn to program web
tutor<br>http://www.freenetpages.co.uk/hp/alan.gauld<br><br><br></blockquote><br><BR><BR>--------------------------------------------------------------------------------------------------------------------------------------<br> "<span id="en-NIV-26403" class="sup"></span>Then you will know the truth, and the truth will set you free."<br> <h3>John 8:32</h3> <span style="font-style: italic;">"</span> As Pastor Niemöller said, first they came for Piglet and I did not speak out because I was not a Disney character."<br> http://www.telegraph.co.uk/opinion/main.jhtml?xml=/opinion/2005/10/04/do0402.xml<br> <br> "When the facts change, I change my opinions, what do you do sir ?" John Keynes.<br> <br> <br><p>
                <hr size=1><font face="Arial" size="2">To help you stay safe and secure online, we've developed the all new <a href="http://us.rd.yahoo.com/mail/uk/taglines/default/security_centre/*http://uk.security.yahoo.com/"><b>Yahoo! Security Centre</b></a>.</font>