[Tutor] Fwd: Simple copy script

Andreas Kostyrka andreas at kostyrka.org
Mon Apr 14 09:29:58 CEST 2008


line.strip()

for line in file: => line will contain '\n' at the end of the string.

Andreas

Am Montag, den 14.04.2008, 00:08 -0700 schrieb Que Prime:
> 
> This is what I came up with after writing it out and reading the
> corresponding functions.  I feel I'm close but something is still
> awry.
> 
> 
> #file copy based on input file containing filenames to be copied
> 
> ##############################
> import os
> import shutil
> 
> os.chdir('c:\\test')
> infile = open("input.txt","r")
> 
> for line in infile:
>   shutil.copy(line, 'outfolder')
>   #print line 'copied'
> infile.close()
> 
> #############################
> 
> ---------- Forwarded message ----------
> From: Alan Gauld <alan.gauld at btinternet.com>
> Date: Sat, Apr 12, 2008 at 5:15 AM
> Subject: Re: [Tutor] Simple copy script
> To: tutor at python.org
> 
> 
> "Que Prime" <queprime at gmail.com> wrote
> 
> 
> > I'm trying to copy files from one directory to another based on an
> > input txt
> > file containing the filename.
> >
> > Source directory = C:\test
> > Destination directory = C:\output
> >
> > input.txt looks like:
> >
> > 12345.pdf
> > 12344.pdf
> 
> 
> Try writing what you want to do in structured English first
> 
> Open the file input.txt
> For each line in input.txt :
>      copy the named file from source to destination
> Close the file input.txt
> 
> Now can you write that ion Python? (You may want to check
> the shutil module for copying the files)
> 
> If you can';t get it to work send us your code and any error
> messages you get.
> 
> You will find more detailed info in the Using the OS
> topic of my tutor.
> 
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://mail.python.org/pipermail/tutor/attachments/20080414/4a76e090/attachment.pgp 


More information about the Tutor mailing list