A script to sort on substrings of the filestem

This simple script allows sorting on substrings of the filestem. For example:

  1. In a directory where many filestems have an eight-digit date at the end, one may want to sort on these last eight characters, and then on the rest of the filestem.
  2. In a directory where filestems begin with a three-digit index, or an eight-digit date, one may want to sort first on the rest of the filestem.
  3. In a directory of downloads where some wretched techie has begun each filename with the date in the form dd-MM-yy, one may want to sort first on the year, then on the month, then on the day, then on the rest of the filename.

Such things are easily done with this script, which by default saves all the user-created "sort configurations" to the one persistent global variable (using vectors), allowing them to be re-used in other directories and after reboot.

  • Everything is controlled by a single command SetupSortConfigs, which has no arguments, and which launches a dialogue that cycles until it is dismissed. On my PC it is launched by a convenient hotkey.

  • A "sort configuration" consists of one or more successive substring specifications, each defined by counting. Multiple substrings are needed for situations such as example 3 above.
    — For each substring, the starting position of each substring is specified by the number of characters skipped.
    — Input 0, 1, 2, 3, ... to count from the left, and -0, -1, -2, -3, ... to count from the right.
    — Then the substring either has a specified length, or continues to the end.
    — The characters of the substring can be reversed, so you can sort by the "metselif".
    [— Each substring is buffered at the right to be the same length for all the files, and "|" is added for clarity and to prevent problems with the sorting of numbers.
    — The full filestem+ext is added at the end to avoid ambiguities caused by identical substrings.]

  • Any newly-created sort configuration automatically becomes the "active configuration" used to sort the lister.
    — But the dialogue displays all the sort configurations, and another can easily be selected as the active configuration.
    — Older, unwanted, sort configurations can be deleted.
    — The dialogue records the directory in which each sort configuration was originally created, but this is for identification only and does not affect the sorting.

  • The sorting is performed by creating a new column called Substrings. This column is automatically turned on and sorted forward when the active configuration is changed or a new sort configuration is created.
    — By default the Substrings column is invisible, being only 1 pixel wide, but it can be made visible from the menu by cycling its length to 80px and 300px so that one can see what is going on.
    — Definitely have a look at the Substrings column at first to watch the process.

  • Three obvious tips:
    — With the column made visible, it is easy to create multiple sorts using Ctrl + mouse.
    — To sort only a subset of the files, first select them and hide the others using the standard DOpus command Select NoPattern HideUnsel.
    — To apply the active sort configuration and column to successive directories, first lock the format using the standard DOpus command Set FormatLock=Toggle.

INSTALLATION:

  • Download the file below, open the scripts window by Preferences --> Toolbars --> Scripts, and drag the downloaded file to its right-hand panel.
  • Somewhere within your menus, create a button whose only command is SetupSortConfigs. Give it a hotkey if you wish.
    SortBySubstringsOfFilestem.js.txt (22.9 KB)