[Tutor] How to list/process files with identical character strings

Marc Tompkins marc.tompkins at gmail.com
Tue Jun 24 21:24:55 CEST 2014


On Tue, Jun 24, 2014 at 8:34 AM, mark murphy <msmurphy at alumni.unc.edu>
wrote:



> What I hope to be able to do is scan the directory, and for each instance
> where there are two files where the first 8 characters (TYYYYDDD) are
> identical, run a process on those two files and place the output (named
> TYYYYDDD) in a new directory.
>
>
I don't know the details of your file system, but I would guess that those
files would have some sort of signifier to indicate "this file is the first
part of a multi-part image"; "this file is the second part", etc. - maybe
the first half has the extension ".001" and the second half has the
extension ".002"?  If so, I would search for files with the "first part"
signifier, and for each one I found I would try to join it with a file with
the same base name but the "second part" signifier.

If, on the other hand, there's no signifier - just the same date but with a
slightly-different timestamp, you can:
1) grab the list of filenames
2) sort it
3) iterate through the list and compare each filename with the previous
filename; if the first 8 characters match, you do your processing magic; if
not, you move on.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140624/6034b785/attachment.html>


More information about the Tutor mailing list