[Tutor] Copy script

Tony Cappellini cappy2112 at gmail.com
Thu Apr 10 15:45:42 CEST 2008


Message: 7
Date: Thu, 10 Apr 2008 01:46:49 +0100
From: "Alan Gauld" <alan.gauld at btinternet.com>
Subject: Re: [Tutor] Copy script
To: tutor at python.org
Message-ID: <ftjo1r$gj6$1 at ger.gmane.org>
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
       reply-type=original

>>I don;t see how the input file relates to the pdf files?
>>Which part of the pdf file does the input numbers refer to?

Kent, I believe the text file contains the name of the text files the author
wants to copy
The problem with the Windows console commands is I don't believe they have
the ability to read files for input.

Que
Here is some code that should get you started.
I don't see the name of the destination directory in your email, so you will
have to edit the variable 'destpath' in the code below
Indenting is likely to get changed during posting, so be aware of that.

import shutil
import os

sourceDir=''

for line in open('input.txt'):
    if not sourceDir and ':' in line:
        sourceDir = line[line.find(':')-1:]

    if 'pdf' in line.lower():
        filename = line.split(' ')[-1]
        sourcePath = os.path.join(sourceDir, filename)
        shutil.copyfile(sourcePath, destPath)
        print'\nCopying %s' % sourcePath


print'\nCopy done'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080410/d5d0d300/attachment.htm 


More information about the Tutor mailing list