<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2800.1528" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=241373612-12022006><FONT face=Verdana color=#0000ff
size=2>David,</FONT></SPAN></DIV>
<DIV><SPAN class=241373612-12022006><FONT face=Verdana color=#0000ff
size=2> in getfiles, the os.getcwd() points the main programs cwd only and
so shutil.copy() fails.</FONT></SPAN></DIV>
<DIV><SPAN class=241373612-12022006><FONT face=Verdana color=#0000ff size=2>so
changing to name = os.path.join(root,name) helps us get the file in the
directory we checked against.</FONT></SPAN></DIV>
<DIV><SPAN class=241373612-12022006><FONT face=Verdana color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=241373612-12022006><FONT face=Verdana color=#0000ff size=2>def
getfiles(file1,file2,top):<BR> for root, dirs, files in
os.walk(top):<BR> for dirname in
dirs:<BR>
print
dirname<BR>
for name in
files:<BR>
if name ==
file1:<BR>
name =
os.path.join(root,name)<BR>
print "the name is" +
name<BR>
shutil.copy(file2,name)<BR>
print "copied one
file"<BR>
print os.getcwd()</FONT></SPAN></DIV>
<DIV><FONT face=Verdana color=#0000ff size=2></FONT> </DIV>
<DIV><SPAN class=241373612-12022006><FONT face=Verdana color=#0000ff
size=2>import os<BR>import shutil<BR>#main<BR>top = r'c:\temp'<BR>a =
os.getcwd()<BR>filename = 'some.txt'<BR>file1 = filename<BR>file2 = a+ os.sep
+filename<BR>print file2<BR>getfiles(filename, file2,top)<BR>print
"finished"<BR></FONT></SPAN></DIV>
<DIV><SPAN class=241373612-12022006><FONT face=Verdana color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=241373612-12022006><FONT face=Verdana color=#0000ff
size=2>thanks!</FONT></SPAN></DIV>
<DIV><SPAN class=241373612-12022006><FONT face=Verdana color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><FONT size=2>--<BR>Senthil<BR> </FONT> </DIV>
<DIV> </DIV><BR>
<BLOCKQUOTE style="MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> tutor-bounces@python.org
[mailto:tutor-bounces@python.org] <B>On Behalf Of </B>David
Holland<BR><B>Sent:</B> Sunday, February 12, 2006 3:40 AM<BR><B>To:</B>
Bruce<BR><B>Cc:</B> tutor python<BR><B>Subject:</B> Re: [Tutor] Change
files<BR></FONT><BR></DIV>
<DIV></DIV>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="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: rgb(16,16,255) 2px solid">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></BLOCKQUOTE></BODY></HTML>