namesort

international anti copyright 2001 matt chisholm
matt (at) theory (dot) org
this program is licensed under the GNU GPL.

Summary

namesort is a python program which sorts a large list of files in a directory into subdirectories based on the filenames. Similarly named files are grouped together. It is especially useful for sorting very large collections of files. There are two sort modes, "strict" and "sloppy". Strict mode sorts files together which share some sequence of the same alphabetic characters. Sloppy mode sorts files together which share some sequence of alphanumerics, followed by the same number of digits, regardless of those digits.

namesort is useful for sorting large collections of files pulled down off of USENET. namesort will sort files into existing directories, if invoked repeatedly on the same directories.

Usage

namesort.py --strict DIRECTORY_1 DIRECTORY_2
namesort.py --sloppy DIRECTORY_1 DIRECTORY_2


DIRECTORY_1 is the directory containing unsorted files. DIRECTORY_2 is the directory into which to sort the files. They may be the same directory; if they are, repeated invocations of namesort will sort previously created directories.

Examples

Say you have the following files in a directory:
23sheep1, 23sheep2, 23sheep3, 24sheep1, 24sheep2, 24sheep3, canal1, canal2, canal3, canal4, cat1, cat2, cat3, collapse, dog1, dog2, dog3, dog4, dog7, dog8, dog9, fat_cat1, fat_cat2, fat_cat3, fat_pig1, fat_pig2, fat_pig3, ferret, fins, fish2, fish3, fish4, fish5, fish7, fish8, fish9, salamander

Strict sort sorts these files into the following directories:

    |-- canal
    |   |-- canal1
    |   |-- canal2
    |   |-- canal3
    |   `-- canal4
    |-- cat
    |   |-- cat1
    |   |-- cat2
    |   `-- cat3
    |-- dog
    |   |-- dog1
    |   |-- dog2
    |   |-- dog3
    |   |-- dog4
    |   |-- dog7
    |   |-- dog8
    |   `-- dog9
    |-- fat_cat
    |   |-- fat_cat1
    |   |-- fat_cat2
    |   `-- fat_cat3
    |-- fat_pig
    |   |-- fat_pig1
    |   |-- fat_pig2
    |   `-- fat_pig3
    `-- fish
        |-- fish2
        |-- fish3
        |-- fish4
        |-- fish5
        |-- fish7
        |-- fish8
        `-- fish9
leaving 23sheep1, 23sheep2, 23sheep3, 24sheep1, 24sheep2, 24sheep3, collapse, ferret, fins, salamander unsorted.

And sloppy sort sorts them into these directories:

    |-- 23sheep
    |   |-- 23sheep1
    |   |-- 23sheep2
    |   `-- 23sheep3
    |-- 24sheep
    |   |-- 24sheep1
    |   |-- 24sheep2
    |   `-- 24sheep3
    |-- canal
    |   |-- canal1
    |   |-- canal2
    |   |-- canal3
    |   `-- canal4
    |-- cat
    |   |-- cat1
    |   |-- cat2
    |   `-- cat3
    |-- dog
    |   |-- dog1
    |   |-- dog2
    |   |-- dog3
    |   |-- dog4
    |   |-- dog7
    |   |-- dog8
    |   `-- dog9
    |-- fat_cat
    |   |-- fat_cat1
    |   |-- fat_cat2
    |   `-- fat_cat3
    |-- fat_pig
    |   |-- fat_pig1
    |   |-- fat_pig2
    |   `-- fat_pig3
    `-- fish
        |-- fish2
        |-- fish3
        |-- fish4
        |-- fish5
        |-- fish7
        |-- fish8
        `-- fish9
leaving collapse, ferret, fins, salamander unsorted.