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.
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.