Bruce,<br> <br> Thanks but is was not the solution. It goes through all the directories but does not seem to work.<br> Here is the modified code :-<br> def getfiles(file1,file2,top):<br> for root, dirs, files in os.walk(top):<br> for name in dirs:<br> print name<br> for name in files:<br> if name == file1:<br> name = os.getcwd()+'/'+name<br> print "the name is" + name<br>
shutil.copy(file2,name)<br> print "copied one file"<br> print os.getcwd()<br> <br> import os<br> import shutil<br> #main<br> top = '/home'<br> a = os.getcwd()<br> filename = 'abcde'<br> file1 = filename<br> file2 = a+'/'+filename<br> print file2<br> getfiles(filename, file2,top)<br> print "finished"<br> <br> David<br> <br><br><b><i>Bruce <epost2@gmail.com></i></b> wrote:<blockquote class="replbq" style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"> I guess that you need to fix two things:<br><br>1 the indentaion error after for name in files:<br><br>2 specify full path for the destination arg in
shutil.copy<br><br><br>On 2/10/06, David Holland <davholla2002 @yahoo.co.uk=""> wrote:<br>> I wrote a little program that replaces all files called 'abcde' with the<br>> file in the directory from which you riun the program. However it does not<br>> find them (there is another one).<br>> What have I done wrong :-<br>> #this program copies the file x to all other places in the directory.<br>> #however it does not go to the right places<br>> def getfiles(file1,file2,top):<br>> for root, dirs, files in os.walk(top):<br>> for name in dirs:<br>> for name in files:<br>> if name == file1:<br>> shutil.copy(file2,name)<br>> print "copied one file"<br>><br>> import os<br>> import shutil<br>> #main<br>> top = '/home'<br>> a = os.getcwd()<br>> filename = 'abcde'<br>> file1 = filename<br>> file2 = a+'/'+filename<br>> getfiles(file1,
file2,top)<br>> print "finished"<br>><br>><br>><br>><br>> ________________________________<br>> To help you stay safe and secure online, we've developed the all new Yahoo!<br>> Security Centre.<br>><br>><br>> _______________________________________________<br>> Tutor maillist - Tutor@python.org<br>> http://mail.python.org/mailman/listinfo/tutor<br>><br>><br>><br></davholla2002></blockquote><br><p>
                <hr size=1><font face="Arial" size="2"><a href="http://us.rd.yahoo.com/mail/uk/taglines/gmail_com/photos/*http://uk.photos.yahoo.com/"><b>Yahoo! Photos</b></a> – <font color="red">NEW</font>, now offering a <a href="http://us.rd.yahoo.com/mail/uk/taglines/gmail_com/photos/*http://uk.photos.yahoo.com/">quality print service</a> from just 8p a photo.</font>