Arrange files according to a text file

MRAB python at mrabarnett.plus.com
Sat Aug 27 13:22:58 EDT 2011


On 27/08/2011 18:03, Ric at rdo.python.org wrote:
> Hello,
>
> What would be the best way to accomplish this task?
> I have many files in separate directories, each file name
> contain a persons name but never in the same spot.
> I need to find that name which is listed in a large
> text file in the following format. Last name, comma
> and First name. The last name could be duplicate.
>
> Adler, Jack
> Smith, John
> Smith, Sally
> Stone, Mark
> etc.
>
>
> The file names don't necessary follow any standard
> format.
>
> Smith, John - 02-15-75 - business files.doc
> Random Data - Adler Jack - expenses.xls
> More Data Mark Stone files list.doc
> etc
>
> I need some way to pull the name from the file name, find it in the
> text list and then create a directory based on the name on the list
> "Smith, John" and move all files named with the clients name into that
> directory.

I would get a name from the text file, eg. "Adler, Jack", and then
identify all the files which contain "Adler, Jack" or "Adler Jack" or
"Jack Adler" in the filename, also checking the surrounding characters
to ensure that I don't split a name, eg. that "John" isn't part of
"Johnson".



More information about the Python-list mailing list