Extreme custom sort

This question may well belong in the 'excessively fiddly and not generally requested' basket, but I dare to ask because with Directory Opus, all sorts of amazing things are possible.

I want to sort the files in a particular folder first on the extension (column heading 'Ext', not 'Type'), secondly on the filename. But I don't want the extension-sort performed either in alphabetical order or in reverse-alphabetical order, because each such sort places often-used files on the second screen of the 100-file folder.

Specifically, I want the extension-groups sorted in the order:
pdf, txt, tex, dvi, log, ptp
(and then the files within each extension group sorted alphabetically).

Is it possible to sort the extension groups by such a custom order?

No, there's no way to sort by extension except alphabetically (or reverse-alphabetically).

If you want to focus your view on certain types, using a filter can make Opus show only the types you want while using (wildcard) labels can let you colour certain types to highlight them next to other files.

Thanks very much for this --- it stops me wondering if I had missed something. And thanks for two very practical ideas.

Perhaps the tweaking of the extension-column sort to a custom order can be added to the suggestion list.

In Dopus 11.5.1 this is now possible.

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

This should do the trick.

[code]
// The OnInit function is called by Directory Opus to initialize the script add-in
function OnInit(initData) {
// Provide basic information about the script by initializing the properties of the ScriptInitData object
initData.name = "Custom Sort Column";
initData.desc = "Adds that allows extension sorting in a custom order";
initData.copyright = "2014 wowbagger";
initData.min_version = "11.5.1"
initData.version = "1";
initData.default_enable = true;

var cmd = initData.AddColumn();
cmd.name = "CustomSort"
cmd.method = "OnCustomSortColumn";
cmd.label = "CustomSort";
cmd.autogroup = true;
cmd.justify = "left";
}

var config = {
sortOrder: [{
extension:"pdf",
sortKey: "1"
}, {
extension:"txt",
sortKey: "2"
}, {
extension:"tex",
sortKey: "3"
}, {
extension:"dvi",
sortKey: "4"
}, {
extension:"log",
sortKey: "5"
}, {
extension:"ptp",
sortKey: "6"
}]
}

// Implement the OnCustomSortColumn column (this entry point is an OnScriptColumn event).
function OnCustomSortColumn(scriptColData) {
// scriptColData is a ScriptColumnData object. first check that this right column
if (scriptColData.col != "CustomSort") return;

var ext = scriptColData.item.ext.replace(".","");
var sortOrder = GetSortOrder(ext);
if (!sortOrder) { 
  scriptColData.value = "";
  scriptColData.sort = 0;
  return;
}
else
{
  scriptColData.value = sortOrder.extension;
  scriptColData.sort = sortOrder.sortKey;
}

}

function GetSortOrder(extension)
{
var match = null;

for(var i = 0; i < config.sortOrder.length; ++i) {
if(config.sortOrder[i].extension == extension) {
match = config.sortOrder[i];
break;
}
}
return match;
}[/code]

I'm confused, wowbagger. With DOpus 11.5.1 installed, I used "SELECT ALL" to copy your script to a button, which I set as a "Script Function". But when I click the button, nothing happens — I was expecting a new column to appear on the right of the current columns.

I can see the setup of the custom order in the lines of the script, and clearly this section can be edited at will once the button is working, but should I be doing something else to make the button work in the first place?

Thanks very much for pursuing this issue from my old posting. I definitely want to solve this problem.

The script needs to be installed as a script add-in, not a button. See gpsoft.com.au/help/opus11/in ... Addins.htm for more information.

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.