Sorting dd mm yyy date

@steje

So now we have script, do you want to add it to Buttons and Toolbars, so that I can tell people where to find it?

I think I have narrowed down the circumstances when running this script may cause DOpus to end under Windows 8.1

If the folder is sorted on Name and the script is run then the problem never occurs.

If the folder is sorted on Description and the script is run then the problem sometimes occurs.

I think it may be connected with the lister display altering the position of files as the script runs and updates the sort field. I say this for two reasons. First you sometimes (not always) see the order of files change just half a second before the problem occurs. Secondly if you have run the script successfully and you run it again on the same unchanged files (so that it is updating the Description field but always to exactly the same value as was there before, and therefore no causing a change in the order of files) the problem does not occur even if you are sorting on Description.

[quote="jjantell"]@steje

So now we have script, do you want to add it to Buttons and Toolbars, so that I can tell people where to find it?[/quote]
I can walk you through adding it to that forum...

OK well I can add it with a note giving you credit for having written it.

Before I add it, would you mind changing the name of the button to "Sort dd-mm-yyyy""

OK thanks. When adding the code to the Buttons and Toolbars forum, how do I create a selectable box to contain the code?

Use [code] tags around it, like this:

Your script ... goes here

[quote="leo"]Use [code] tags around it, like this:

Your script ... goes here[/quote]

Thanks, Leo.

Now all I need is for the name of the button to be changed from "Filename to Desc" to something more descriptive of its overall purpose: "Sort dd-mm-yyyy". I can see that the words "Filename to Desc" appear in the script a couple of times but I hesitate to change anything myself as I would not know what I was doing.

Regarding the problem with DOpus ending part way through the script, I am 99% sure now that this is connected to the sort field. In earlier posts I said I thought it had something to do with folder names but I think now that that was just a co-incidence with different folder names using different folder options and hence different sort fields.

The problem occurs if Description is set as the sort field before the script is run. As the script runs and populates the Description field, DOpus alters the position of the files and for some reason this causes DOpus to crash (under Windows 7) or to simply end without an error message (under Windows 8.1).

If the sort field is set to anything else, Name for example, then the script runs fine (and, of course, after running the script, you can then set Description as the sort field).

In customise mode, edit the button text then right click on the button and select copy... your new code in now in the clipboard... paste into the forum and that's it. I could do it for you but once you try it yourself, you'll realise how simple it is...even I can do it :slight_smile:

Failing that, I'll do it for you.

Would you mind doing it - just don't want to change the wrong thing!

Also it occurs to me that with the problem of DOpus crashing if Description is the sort field when the script is running, would it be possible to add a line at the start of the script setting the sort field to Name, and add a line at the end of the script setting the sort field to Description.

Would you mind doing it - just don't want to change the wrong thing!

Also it occurs to me that with the problem of DOpus crashing if Description is the sort field when the script is running, would it be possible to add a line at the start of the script setting the sort field to Name, and add a line at the end of the script setting the sort field to Description.[/quote]
I have edited the button labels as requested but I am unsure about the sort commands. I have tried adding "Set Sortby=name" to the start of the code which works but adding "Set Sortby=desc" to the end of the code doesn't work. I'm sure someone else on here can help you with that one.

I have sent you a PM rather than clogging up the post with "incomplete" code which will ultimately end up in the "Buttons & Toolbars" section anyway, plus a link to a YouTube video showing how easy this is. Good luck with the rest of it.

<?xml version="1.0"?> <button backcol="none" display="both" label_pos="right" separate="yes" 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>Rename PATTERN=&quot;*&quot; TO=&quot;*&quot;</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; https://resource.dopus.com/t/abusing-rename-scripts-to-do-other-things-with-file-info/5969/1 <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> <instruction>Set SORTBY=desc </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>SetAttr SETDESCRIPTION</instruction> </function> </button> </button>

Blueroly has very helpfully provided this code. The button has the right name. It begins by setting sort to "Name". The only thing it does not do is set sort to "Description" at the end. You can see the Set SORTBY=desc at the end but for some reason this does not work - i.e. it has no effect. Does anyone know why?

All the commands need to be before the script. The script is used by the Rename command and should come after everything else.

So I think you just need to move that Set SORTBY=desc line from the very bottom up to near the top, putting it after the Rename ... line and before the @script vbscript line.

[quote="leo"]All the commands need to be before the script. The script is used by the Rename command and should come after everything else.

So I think you just need to move that Set SORTBY=desc line from the very bottom up to near the top, putting it after the Rename ... line and before the @script vbscript line.[/quote]

<?xml version="1.0"?> <button backcol="none" display="both" label_pos="right" separate="yes" 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>Rename PATTERN=&quot;*&quot; TO=&quot;*&quot;</instruction> <instruction>Set SORTBY=desc </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; https://resource.dopus.com/t/abusing-rename-scripts-to-do-other-things-with-file-info/5969/1 <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>SetAttr SETDESCRIPTION</instruction> </function> </button> </button>

I think I have done what you suggested. Is this correct? It seems to work.

I have tried to add an entry in the Buttons forum... not very well, but blueroly has now done it properly for me (though how he managed to do that with the post author still shown as me I am not quite sure!).

Anyway, thank you blueroly

[quote="jjantell"]I have tried to add an entry in the Buttons forum... not very well, but blueroly has now done it properly for me (though how he managed to do that with the post author still shown as me I am not quite sure!).

Anyway, thank you blueroly[/quote]
I didn't. Without your login details or admin rights it's impossible for me to do that anyway.

[quote="blueroly"][quote="jjantell"]I have tried to add an entry in the Buttons forum... not very well, but blueroly has now done it properly for me (though how he managed to do that with the post author still shown as me I am not quite sure!).

Anyway, thank you blueroly[/quote]
I didn't. Without your login details or admin rights it's impossible for me to do that anyway.[/quote]

Well someone did, just after your PM in which you pointed out some desirable changes - e.g not assuming, in the instructions, that the files were PDFs etc.... Perhaps it was leo?

Thank you to everyone who contributed to producing this button.

I am sure it will prove very useful as many people need the facility which it provides.

For anyone who is interested, this is the page on my website which links to it:

http://www.johnantell.co.uk/inform■■■■ation-in-England-and-Wales/how-to-create-a-court-bundle/sorting-dd-mm-yyyy-files-chronologically

[quote="jjantell"]Regarding the problem with DOpus ending part way through the script, I am 99% sure now that this is connected to the sort field. In earlier posts I said I thought it had something to do with folder names but I think now that that was just a co-incidence with different folder names using different folder options and hence different sort fields.

The problem occurs if Description is set as the sort field before the script is run. As the script runs and populates the Description field, DOpus alters the position of the files and for some reason this causes DOpus to crash (under Windows 7) or to simply end without an error message (under Windows 8.1).

If the sort field is set to anything else, Name for example, then the script runs fine (and, of course, after running the script, you can then set Description as the sort field).[/quote]

Many thanks for these details. With them we were able to track down the cause of the crash and fix it. The fix should be in the next update.

(Even with the fix, you may still want to keep the button working as it does right now, as it may be nicer visually, and could also speed things up very slightly, to re-sort all the items once at the end instead of for each file as it is processed by the script.)

[quote="leo"]Many thanks for these details. With them we were able to track down the cause of the crash and fix it. The fix should be in the next update.

(Even with the fix, you may still want to keep the button working as it does right now, as it may be nicer visually, and could also speed things up very slightly, to re-sort all the items once at the end instead of for each file as it is processed by the script.)[/quote]

That is good news. Meanwhile I have come across some situations where a failure still occurs (notwithstanding that Desc is not set as the sort field until the end of the script).

I am still trying to establish the patten for this but I have noticed that some folders have a descript ION file in them and some do not.

Should I be seeing a ION file in every folder when the Description field is used?