Sort dd-mm-yyyy

Note for Directory Opus 11 & above:

You can now do this kind of thing better using a script column, to avoid having to set any file descriptions.

You can find examples similar to this via the scripting and column tags.

Original post:

Got some files with names commencing dd-mm-yyyy

Want them to appear in chronological order?

This button will do it.

It works by finding the date in each filename, setting each file's Description field to the date in yyyy-mm-dd format, and then sorting by the Description column.

Created by: steje - with modifications by blueroly and leo

Here is the button XML code.

See How to add buttons from this forum to your toolbars for instructions on how to paste the XML code to your toolbar.

<?xml version="1.0"?> <button backcol="none" display="both" label_pos="right" textcol="none" type="three_button"> <label>Sort dd-mm-yyyy</label> <icon1>#default:recentlistclear</icon1> <button backcol="none" display="both" label_pos="right" textcol="none"> <label>Sort dd-mm-yyyy</label> <tip>Use a dd-mm-yyyy filename string to set a yyyy-mm-dd Description field value.</tip> <icon1>#default:recentlist</icon1> <function type="normal"> <instruction>Set SORTBY=name </instruction> <instruction>Set COLUMNSADD userdesc SORTREVERSE=off</instruction> <instruction>Rename FROM *.* PATTERN=&quot;*&quot; TO=&quot;*&quot;</instruction> <instruction>Set SORTBY=userdesc </instruction> <instruction>@script vbscript</instruction> <instruction>Option Explicit</instruction> <instruction>&apos; For information on the technique used in this button see:</instruction> <instruction>&apos; &quot;Abusing&quot; Rename Scripts to do other things with file info</instruction> <instruction>&apos; <instruction>&apos; Change the path below if you haven&apos;t installed Opus to the default location:</instruction> <instruction>dim DOpusRTPath</instruction> <instruction>DOpusRTPath = &quot;%ProgramFiles%\GPSoftware\Directory Opus\dopusrt.exe&quot;</instruction> <instruction>Dim Shell</instruction> <instruction>Set Shell = CreateObject(&quot;WScript.Shell&quot;)</instruction> <instruction>Dim re</instruction> <instruction>Set re = new RegExp</instruction> <instruction>Function Rename_GetNewName(strFileName, strFilePath, fIsFolder, strOldName, ByRef strNewName)</instruction> <instruction> Dim strDate</instruction> <instruction> Dim strCommand</instruction> <instruction> &apos; Set strNewName to an empty string so that Opus does not rename the file.</instruction> <instruction> strNewName = &quot;&quot;</instruction> <instruction> re.IgnoreCase = True</instruction> <instruction> re.Global = False</instruction> <instruction> &apos; The strFileName, we have should be something like &quot;29-07-2011 other_filename_text.ext&quot;</instruction> <instruction> re.Pattern = &quot;(\d\d)-(\d\d)-(\d\d\d\d)(.*)&quot;</instruction> <instruction> If (re.Test(strFileName)) Then</instruction> <instruction> &apos; Set strDate to a string like &quot;2011-07-29&quot;</instruction> <instruction> strDate = re.Replace(strFileName, &quot;$3-$2-$1&quot;)</instruction> <instruction> &apos; DOpus.OutputString &quot;DT = &quot; &amp; strDate</instruction> <instruction> strCommand = &quot;&quot;&quot;&quot; &amp; DOpusRTPath &amp; &quot;&quot;&quot; /cmd SetAttr FILE=&quot;&quot;&quot; &amp; strFilePath &amp; &quot;\&quot; &amp; strFileName &amp; &quot;&quot;&quot; DESCRIPTION=&quot;&quot;&quot; &amp; strDate &amp; &quot;&quot;&quot;&quot;</instruction> <instruction> &apos; DOpus.OutputString &quot;CMD = &quot; &amp; strCommand</instruction> <instruction> Shell.Run strCommand,0,true</instruction> <instruction> End If</instruction> <instruction>End Function</instruction> </function> </button> <button backcol="none" display="both" label_pos="right" textcol="none"> <label>Clear Desc</label> <icon1>#default:recentlistclear</icon1> <function type="normal"> <instruction>Set SORTBY=name </instruction> <instruction>SetAttr SETDESCRIPTION</instruction> </function> </button> </button>

Once the Sort dd-mm-yyyy button is installed, simply press it when listing any folder containing file names commencing dd-mm-yyyy, and the files will be listed in chronological order.


  1. When you press the button, for every file name commencing with dd-mm-yyyy date, the button will overwrite any existing value in the Description field, so make sure the Description field is not being used for anything else.

  2. You can clear the Description field from selected file(s), by selecting the files(s) and Right-clicking the button.

  3. The button accepts 00 values for day and month so, for example, if you have only an approximate date, e.g. June 2013, you can start the file name with e.g. 00-06-2013 and the file will sort to the approximately correct chronological position.

  4. Remember the note at the top of the page: Newer versions of Opus have a nicer way of achieving this.

Related to this:

[ul][li]If you want to set the Date Modified timestamps on the files, based on the dates in the filenames, see: File name to Modified Date/Time.[/li]
[li]If you want to set the Date Modified timestamps from EXIF shooting times, or vice versa, see: Copy Created/Modified times to/from EXIF times.[/li][/ul]

Depending on what you are doing, those may be preferable since they allow you to sort by the normal date fields, which will work both in and outside of Opus, without modifying the file descriptions.

Thank you