[Tutor] Copy script
Kent Johnson
kent37 at tds.net
Thu Apr 10 04:14:11 CEST 2008
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
000012347425 [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 000000011479
> [7ac0c741-9d2f-4a1d-9dbf-8de27ca0abb4].pdf
> 03/20/2008 09:21 AM 154,655 000000011600
> [cd752a5a-388a-4bad-9a52-fb3711f685b8].pdf
> 03/20/2008 09:21 AM 145,556 000000015234
> [4344f5ff-fa58-4e20-bf27-697c71a81fbc].pdf
> 03/20/2008 09:21 AM 152,785 000012347424
> [44cc0d43-a80d-4415-8e92-b6a4f62986b4].pdf
> 03/20/2008 09:21 AM 145,551 000012347425
> [0ea7b60a-3631-4f64-91fa-6e385296f18f].pdf
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list