Extreme custom sort

Thanks, Jon, but you may be assuming that I know more than I acually do.

  • I used "SELECT ALL" to copy wowbagger's script to a text file.
  • I renamed the text file "Custom_Sort_Column.js" (because *.vbs wouldn't install).
  • I dragged the file into the window at Preferences - - > Toolbars - - > Scripts. This has caused a file "Custom_Sort_Column.vbs" to appear in C:\GPSoftware\Directory Opus\Script Addins, and a script named "Custom Sort Column 1" to appear in the window at Preferences - - > Toolbars - - > Scripts.
  • I then created a "Standard Function" button with the command $Custom_Sort_Button. When I click on this button, however, I get an error message beginning, "Windows cannot find $Custom_Sort_Button." I changed the command to $CustomSort (as in cmd.name within the script) and to $Custom Sort Button (as in initData.name), but no luck.

Apologies for not catching on. I read the help page you gave and tried various other things, but I couldn't get any further clues.

I've got butterfingers. In the third starred point above, the filename should be Custom_Sort_Column.js, not Custom_Sort_Column.vbs.

You're still trying to use it as a button. It's not a button, it's a column :slight_smile:
Add it to the file display like any other column (Name, Date, Size, etc).

Aaaaahhhh!!! I understand now why DOpus has a shining light bulb for its icon! Thank you very much indeed, wowbagger for your script, and Jon for your patience.

Sorry I should have given more details, glad you got it sorted.

[quote="wowbagger"]You can create a custom column and set the sort order based on the extension. Then first sort by the custom column and set the name column as the second sort order (control click the heading).
[/quote]
This is a good one.. It basically means that it is possible to sort the files in any way you want as long as you can define something to base the sort
on through a script. There was someone that asked for sorting on partial/reordered filenames or whatever some time ago, and this can do exactly that.

While entering this reply I made one such script myself..and now I'm finally able to sort a set of files like I want to.
It was in the format "ttttttt nnnnnn-xxx.txt", where I wanted to sort on the "xxx" portion of the filename.
Just a simple regex to extract that portion, and viola..

The custom column is an answer to a lot of peoples questions for sure. If you can find that old post, we/I can create a script for them. Getting out a few examples of how to use the new feature will help others find their way.

Myarmor, sounds good, would you mind sharing your script? Custom Column - Example custom sort
PS, there is no such thing as Just a simple regex :wink:

It might be Filenames that display as three columns

Thanks once again, wowbagger. I now have replaced the ordinary Ext column with the Custom Sort column in the large special directory where I want all subdirectories sorted in the same custom way. There were more different extensions than I realised, so I have greatly expanded the short list at the start of your macro, leaving gaps of the form
}, {
extension:"",
sortKey: "19"
for any later extensions that may turn up. Here are some perfectionist remarks about some other details that I don't know how to edit.

  1. Contrary to what I had expected, editing a line to
    extension:"",
    doesn't affect the sorting of files without extension. Whether or not this line occurs, and wherever it occurs, files without extension are all sorted to the top (or to the bottom if the sorting is reversed). It would be useful if any files without extension could be sorted in the same way as other files.

  2. The line
    extension:"txt"
    does not sort files with uppercase extension TXT. I fixed this very quickly by using DOpus' Advanced Rename to convert all extensions in my special directory to lowercase, but it could be useful if the script treated as one all the forms: txt, TXT, Txt, TxT, tXT, . . .

  3. When I change a file's extension, the extension in the ordinary Ext column changes immediately, but the extension in the CustomSort column only changes when I refresh the display with the "Go Refresh=All" button (or change directory away and back again). Is there a "Refresh" command that can be added to the script?

  4. Each time I add lines to the list of extensions, I seem to have to delete and then reinstall the script in Preferences - - > Toolbars - - > Scripts. That's no great pain, and I expect that it's not worth writing extra code for the "Configure" facility in the "Configure" box of the "Scripts" window. But if others are going to use the script as a basis for more complex sortings, maybe there is a case for it.

  5. I expect that if one wanted to have two or more different custom sorts available, it would only be a matter of changing a few names within the script. I've already changed the column heading to CS because of the narrowness of the extension column.

  6. . . . and a question. The command
    Set COLUMNSTOGGLE="scp:Custom Sort Column/CustomSort"
    toggles the new column. But how do I control where and how wide the new column is? I tried adding the usual (*,36) before and after the last " sign, but no luck.

FILES WITHOUT EXTENSION: My apologies, I was wrong about point 1 above. Editing a line to an empty extension as
extension:"",
behaves exactly the same as any other extension. Thus the group of files without extension can be sorted the same as all other groups of files.

#3 requires an enhancement to the column system to allow refreshing a column when a filename changes, we will add this in the next update.
#6 is a bug, fixed in the next update.

Thanks, Jon. As regards point 6, I should report that I later tried adding ,name to the standard sort so as to create a button that sorted first on the Custom Sort, and then on the filename. Again, no luck, even though I tried adding it both before and after the second " symbol.

I had no problems, however, when I used the standard "Formats" screen to remove the standard Ext column, then add the Custom Sort column, specify its width as 36, and move it into the position previously occupied by Ext. Also, I could then specify the sort as first by the Custom Sort and secondly by the filename.

Can you post the command you tried?

I updated the script to version 1.1 you can see it here.

[quote="Julianon"]1. Contrary to what I had expected, editing a line to extension:"", doesn't affect the sorting of files without extension. Whether or not this line occurs, and wherever it occurs, files without extension are all sorted to the top (or to the bottom if the sorting is reversed). It would be useful if any files without extension could be sorted in the same way as other files.[/quote]This should work, at least it does now. Folders still group together but files with no extension obey the sort order. I added a debug flag that will display the sort order in the column with the text so you can see if its not matching.

[quote="Julianon"]2. The line extension:"txt" does not sort files with uppercase extension TXT. I fixed this very quickly by using DOpus' Advanced Rename to convert all extensions in my special directory to lowercase, but it could be useful if the script treated as one all the forms: txt, TXT, Txt, TxT, tXT, . . .[/quote]This is fixed in the new version. Thanks for pointing it out.

[quote="Julianon"]4. Each time I add lines to the list of extensions, I seem to have to delete and then reinstall the script in Preferences - - > Toolbars - - > Scripts. That's no great pain, and I expect that it's not worth writing extra code for the "Configure" facility in the "Configure" box of the "Scripts" window. But if others are going to use the script as a basis for more complex sortings, maybe there is a case for it.[/quote]I notice I need to remove and re-dd the column sometimes. Sometimes I close the tab and open a new also to remove "ghost" tabs. I never need to disable and re-enable the script.

[quote="Julianon"]5. I expect that if one wanted to have two or more different custom sorts available, it would only be a matter of changing a few names within the script. I've already changed the column heading to CS because of the narrowness of the extension column.[/quote]The new version allows you to define multiple columns. Thanks for the suggestion.

Jon, the two commands that I tried were:
Set SORTBY="scp:Custom Sort Column/CustomSort,Name" SortReverse=ToggleSmart
Set SORTBY="scp:Custom Sort Column/CustomSort",Name SortReverse=ToggleSmart
Omitting SortReverse=ToggleSmart didn't help either.

Wowbagger, I'll check through the various changes to the script in the morning.

Thanks, wowbagger. That seems to account for every detail that I can identify, apart from the things that Jon says need to be sorted out within DOpus. Hopefully the script is now so general that it should be useful in all sorts of other situations.

The business of uppercase extensions raises a question — is there any software on the planet that is case-sensitive to the extension? I ask this because your script nukes the annoying uppercase completely and lists, for example, MyFile.TXT as MyFile.txt. (That's if I hide filename extensions and place the custom column next after the filename.)

Set SORTBY problem fixed in the next update.

The column shows the value from the config not the file extension, the files extension is not being altered.

Jon, thanks very much for all this. Reporting on the new update V11.5.2:

  1. The following command now successfully adds the custom column as a final column, with width 32:
    Set COLUMNSTOGGLE="scp:Custom Sort Column/CS1(*,32)"
    Changing * to say 3 adds it after the 3rd column. The " symbol must go at the end, not after CS1, and the two " symbols cannot be omitted.

  2. The following command now successfully sorts first on the custom sort column and then on the filename:
    Set SORTBY="scp:Custom Sort Column/CS1,Name"
    Again, the " symbol must come at the end.

Adding SortReverse=ToggleSmart doesn't work, but I think SortReverse=ToggleSmart was never supposed to work with more than one sort column.

  1. Point 3 of my earlier post remains unfixed at this stage:

[quote]When I change a file's extension, the extension in the ordinary Ext column changes immediately, but the extension in the CustomSort column only changes when I refresh the display with the "Go Refresh=All" button (or change directory away and back again).
[/quote]


By the way, I have versions 1 and 1.1 of wowbagger's script installed at the moment. — I have changed the column heading in Ver 1 to CS and the column headings in Ver 1.1 to CS1 and CS2. Changing CS1 to CS or to CS2 in both Set COLUMNSTOGGLE and Set SORTBY works just as well (on the different columns). All three headings are available when using the Commands and Arguments picker in the function editor.


wowbagger, I know that the file's extension is not being changed from upper to lower case. I should have explained the further point that getting rid of the extension column, and relying only on the Custom Sort column, hides the fact that some of the extensions may be uppercase — but in Windows, who cares anyway?

Point 3 will require an update to the script to set the new flag telling Opus it needs to refresh when the filename changes.