[Tutor] Fwd: Simple copy script

Que Prime queprime at gmail.com
Mon Apr 14 09:08:52 CEST 2008


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080414/64d5fd45/attachment.htm 


More information about the Tutor mailing list