Re: [Tutor] Copy script
could you do a : dir /b inside this directory just so that we can know the real file names. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Copy script
Message: 7 Date: Thu, 10 Apr 2008 01:46:49 +0100 From: Alan Gauld [EMAIL PROTECTED] Subject: Re: [Tutor] Copy script To: tutor@python.org Message-ID: [EMAIL PROTECTED] 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' ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Copy script
Tony Cappellini [EMAIL PROTECTED] wrote 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 Actually that was me :-) The problem with the Windows console commands is I don't believe they have the ability to read files for input. Of course they do - they can use input redirection just like Unix. But the FOR /F option I mentioned is explicitly for iterating over the contents of a text file. And of course you can use backticks(`) to TYPE a file into a command, in place of a file list, say. The XP command line tools are much better than the early DOS stuff - although still nowhere near to Unix shells. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Copy script
Of course they do - they can use input redirection just like Unix. Oh,-I have forgotten about that. But why use clunky batch language when you can use Python? After all, he did post this to the python list. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Copy script
I have a folder of 150,000 pdf files and I need to copy 20,000 of them to another folder. The ones I need to copy are in a .txt file. Attached is a sample of the input .txt file and a dos directory of the folder containing the files. I'm not sure of the best way to accomplish this. Thank you in advance for your help. Sample input file: 12347424 12347425 12347426 12347427 Sample dir on folder: 03/20/2008 09:21 AM 145,257 00011479 [7ac0c741-9d2f-4a1d-9dbf-8de27ca0abb4].pdf 03/20/2008 09:21 AM 154,655 00011600 [cd752a5a-388a-4bad-9a52-fb3711f685b8].pdf 03/20/2008 09:21 AM 145,556 00015234 [4344f5ff-fa58-4e20-bf27-697c71a81fbc].pdf 03/20/2008 09:21 AM 152,785 12347424 [44cc0d43-a80d-4415-8e92-b6a4f62986b4].pdf 03/20/2008 09:21 AM 145,551 12347425 [0ea7b60a-3631-4f64-91fa-6e385296f18f].pdf Volume in drive C has no label. Volume Serial Number is 0873-E099 Directory of C:\Documents and Settings\test 04/09/2008 03:57 PMDIR . 04/09/2008 03:57 PMDIR .. 03/20/2008 09:21 AM 145,647 0737 [f05d4dcc-8c0e-4660-b9f7-83708dfc782e].pdf 03/20/2008 09:21 AM 144,945 1237 [b951dfd8-af0e-4243-9951-0cf63b7f5f1a].pdf 03/20/2008 09:21 AM 145,984 1491 [7a9d5843-55d7-4a37-9903-a210ff538d12].pdf 03/20/2008 09:21 AM 145,644 1777 [dd9b13cc-f088-4957-a2df-a9dac2959e81].pdf 03/20/2008 09:21 AM 145,730 1995 [cb12e1ef-074a-4b41-abfc-6aa2048d5008].pdf 03/20/2008 09:21 AM 149,319 2609 [dc64fabf-fe2f-47bf-90a4-f1eef43586d6].pdf 03/20/2008 09:21 AM 145,994 2789 [b7242dd2-cfa9-435c-a8f7-05d9d500dbcc].pdf 03/20/2008 09:21 AM 145,788 4169 [9ed9f002-12e2-4a7a-952e-2d2a5a44b775].pdf 03/20/2008 09:21 AM 152,189 4247 [18b05f77-d429-4231-8e99-541e07613e3a].pdf 03/20/2008 09:21 AM 161,951 8623 [decd3cb9-c6bf-4d17-9bdd-cb1d63023aeb].pdf 03/20/2008 09:21 AM 147,243 00010957 [1ae26ed1-8114-49ab-9eeb-40f636ffd257].pdf 03/20/2008 09:21 AM 145,257 00011479 [7ac0c741-9d2f-4a1d-9dbf-8de27ca0abb4].pdf 03/20/2008 09:21 AM 154,655 00011600 [cd752a5a-388a-4bad-9a52-fb3711f685b8].pdf 03/20/2008 09:21 AM 145,556 00015234 [4344f5ff-fa58-4e20-bf27-697c71a81fbc].pdf 03/20/2008 09:21 AM 152,785 12347424 [44cc0d43-a80d-4415-8e92-b6a4f62986b4].pdf 03/20/2008 09:21 AM 145,551 12347425 [0ea7b60a-3631-4f64-91fa-6e385296f18f].pdf 04/09/2008 03:57 PM 0 dir.txt 17 File(s) 2,374,238 bytes 2 Dir(s) 39,714,271,232 bytes free 12347424 12347425 12347426 12347427 12347428 12347429 12347430 12347431 12347432 12347433 12347434 12347435 12347437 12347438 12347439 12347440 12347442 12347443 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Copy script
Que Prime [EMAIL PROTECTED] wrote I have a folder of 150,000 pdf files and I need to copy 20,000 of them to another folder. The ones I need to copy are in a .txt file. Sounds straightforward but... Attached is a sample of the input .txt file and a dos directory of the folder containing the files. I'm not sure of the best way to accomplish this. Thank you in advance for your help. Sample input file: 12347424 12347425 Sample dir on folder: 03/20/2008 09:21 AM 145,257 00011479 [7ac0c741-9d2f-4a1d-9dbf-8de27ca0abb4].pdf 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? However it may be that the DOS FOR command with the /F option may be adapted to do what you want. It iterates over the content of a file performing a command per item in the file... Try Help FOR to get more info and try experimenting... DOS is a braindead beast but does sometimes have the facilities needed... The XP DOS commands are considerably more powerful than the old DOS set. Some of them even have a Unix like backtick facility! -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Copy script
Alan Gauld wrote: "Que Prime" [EMAIL PROTECTED] wrote I have a folder of 150,000 pdf files and I need to copy 20,000 of them to another folder. The ones I need to copy are in a .txt file. Sounds straightforward but... Attached is a sample of the input .txt file and a dos directory of the folder containing the files. I'm not sure of the best way to accomplish this. Thank you in advance for your help. Sample input file: 12347424 12347425 Sample dir on folder: 03/20/2008 09:21 AM 145,257 00011479 [7ac0c741-9d2f-4a1d-9dbf-8de27ca0abb4].pdf 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? There was a time in the good old days that programmers knew about writing specifications. Nowadays specification by example seems to be the defacto standard. Sigh. I can guess that given 03/20/2008 09:21 AM 152,785 12347424 [44cc0d43-a80d-4415-8e92-b6a4f62986b4].pdf 12347424 [44cc0d43-a80d-4415-8e92-b6a4f62986b4].pdf is the file name. I happen to notice that 12347424 appears in the input file and in the assumed file name. So the specification *might be* choose files where characters 5-12 of the name match the eight characters of a line of the input file. Wouldn't it be nice if the asker of the question were to say "yes that is correct" or "no and here is the correct specification". It would have been even nicer if he/she had given the specification the first time. Would have saved everyone time and helped ensure a quick and correct answer. -- Bob Gailer 919-636-4239 Chapel Hill, NC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Copy script
Que Prime wrote: I have a folder of 150,000 pdf files and I need to copy 20,000 of them to another folder. The ones I need to copy are in a .txt file. Attached is a sample of the input .txt file and a dos directory of the folder containing the files. I'm not sure of the best way to accomplish this. So a sample filename is 12347425 [0ea7b60a-3631-4f64-91fa-6e385296f18f].pdf and you would want to copy this because 12347425 is in the txt file? If that is correct understanding, I think I would - read the txt file and put all the numbers in a set. - iterate through the file names in the source dir - isolate the initial number part of the file name, strip the leading 0's - check if the initial number is in the set - if so, then copy the file Are all the files in one directory? If so I guess you will have to have enough memory to hold all the file names (as well as the set of numbers) and probably a bit of patience! I don't know a way to generate the sequence without creating the full list. Kent Thank you in advance for your help. Sample input file: 12347424 12347425 12347426 12347427 Sample dir on folder: 03/20/2008 09:21 AM 145,257 00011479 [7ac0c741-9d2f-4a1d-9dbf-8de27ca0abb4].pdf 03/20/2008 09:21 AM 154,655 00011600 [cd752a5a-388a-4bad-9a52-fb3711f685b8].pdf 03/20/2008 09:21 AM 145,556 00015234 [4344f5ff-fa58-4e20-bf27-697c71a81fbc].pdf 03/20/2008 09:21 AM 152,785 12347424 [44cc0d43-a80d-4415-8e92-b6a4f62986b4].pdf 03/20/2008 09:21 AM 145,551 12347425 [0ea7b60a-3631-4f64-91fa-6e385296f18f].pdf ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Copy script
Alan Gauld wrote: Que Prime [EMAIL PROTECTED] wrote I have a folder of 150,000 pdf files and I need to copy 20,000 of them to another folder. The ones I need to copy are in a .txt file. Assuming the text file is a list of those to be copied, wouldn't a simple bash script do the trick? (don't know about windows, but this would work on Mac or Linux, and, I assume there must be a way to do this with a windows command line script of some sort.) #!/bin/bash cd /path/to/dir/with/files/and/list llistofiles=$(cat your .txt file here) echo Copying files... for each i in $listofiles do cp $i /path/to/other/folder/$i echo All done...b'bye... exit Or, perhaps with tcl #!/usr/bin/wish set listofiles [read your txt file here] puts Copying files... foreach a {$listofiles} { file copy $a /path/to/target/dir } puts All done...b'bye... exit I imagine python could do something quite similar, but confess I am just lurking on this list and have barely begun to learn python. /tony -- Anthony Baldwin http://www.BaldwinLinguas.com Translation Interpreting http://www.TransProCalc.org Free translation project mgmt software http://www.LinguasOS.org Linux for Translators ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor