<!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>&nbsp;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&nbsp;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>&nbsp;</DIV>
<DIV><SPAN class=241373612-12022006><FONT face=Verdana color=#0000ff size=2>def 
getfiles(file1,file2,top):<BR>&nbsp;&nbsp;&nbsp; for root, dirs, files in 
os.walk(top):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for dirname in 
dirs:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
print 
dirname<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
for name in 
files:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
if name == 
file1:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
name = 
os.path.join(root,name)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
print "the name is" + 
name<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
shutil.copy(file2,name)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
print "copied one 
file"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
print os.getcwd()</FONT></SPAN></DIV>
<DIV><FONT face=Verdana color=#0000ff size=2></FONT>&nbsp;</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>&nbsp;</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>&nbsp;</DIV>
<DIV><FONT size=2>--<BR>Senthil<BR>&nbsp;</FONT> </DIV>
<DIV>&nbsp;</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.&nbsp; 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>&nbsp;&nbsp;&nbsp; for root, 
  dirs, files in os.walk(top):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for 
  name in 
  dirs:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  print 
  name<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for 
  name in 
  files:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  if name == 
  file1:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  name = 
  os.getcwd()+'/'+name<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  print "the name is" + 
  name<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  shutil.copy(file2,name)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  print "copied one 
  file"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  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 
  &lt;epost2@gmail.com&gt;</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>&gt; I wrote a little program that replaces all 
    files called 'abcde' with the<BR>&gt; file in the directory from which you 
    riun the program. However it does not<BR>&gt; find them (there is another 
    one).<BR>&gt; What have I done wrong :-<BR>&gt; #this program copies the 
    file x to all other places in the directory.<BR>&gt; #however it does not go 
    to the right places<BR>&gt; def getfiles(file1,file2,top):<BR>&gt; for root, 
    dirs, files in os.walk(top):<BR>&gt; for name in dirs:<BR>&gt; for name in 
    files:<BR>&gt; if name == file1:<BR>&gt; shutil.copy(file2,name)<BR>&gt; 
    print "copied one file"<BR>&gt;<BR>&gt; import os<BR>&gt; import 
    shutil<BR>&gt; #main<BR>&gt; top = '/home'<BR>&gt; a = os.getcwd()<BR>&gt; 
    filename = 'abcde'<BR>&gt; file1 = filename<BR>&gt; file2 = 
    a+'/'+filename<BR>&gt; getfiles(file1, file2,top)<BR>&gt; print 
    "finished"<BR>&gt;<BR>&gt;<BR>&gt;<BR>&gt;<BR>&gt; 
    ________________________________<BR>&gt; To help you stay safe and secure 
    online, we've developed the all new Yahoo!<BR>&gt; Security 
    Centre.<BR>&gt;<BR>&gt;<BR>&gt; 
    _______________________________________________<BR>&gt; Tutor maillist - 
    Tutor@python.org<BR>&gt; 
    http://mail.python.org/mailman/listinfo/tutor<BR>&gt;<BR>&gt;<BR>&gt;<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> &#8211; <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>