[Tutor] Change files

David Holland davholla2002 at yahoo.co.uk
Fri Feb 10 22:51:00 CET 2006


I wrote a little program that replaces all files called 'abcde' with the file in the directory from which you riun the program.  However it does not find them (there is another one).
 What have I done wrong :-
 #this program copies the file x to all other places in the directory.
 #however it does not go to the right places
 def getfiles(file1,file2,top):
     for root, dirs, files in os.walk(top):
         for name in dirs:
             for name in files:
         if name == file1:
             shutil.copy(file2,name)
                     print "copied one file"
       
 import os
 import shutil
 #main
 top = '/home'
 a = os.getcwd()
 filename = 'abcde'
 file1 = filename
 file2 = a+'/'+filename
 getfiles(file1, file2,top)
 print "finished"
 
 
 
		
---------------------------------
To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060210/738ff9e6/attachment.htm 


More information about the Tutor mailing list