Sorting dd mm yyy date

@michaelkenward: yeah, I "get it"... Americans do things weird. I'm an American, and it's really not a "many people may not agree with" me sort of thing so much as simply a learned behavior. My point was - at the end of the day, the selfsame ~american users who might otherwise have the mm/dd/yyyy convention stuck in their brain need look no further than the exact situation that the OP is trying to solve in order to understand why it's friendlier to the purpose of sorting to name files in yyyy-mm-dd convention rather than what we've grown up being used to. Further to the point I was commenting that even if such users don't appreciate the benefit of doing so, compared to the relative "hassle" of having to take manual action in order to see the sorting in a way that makes sense... as obstinate as we can be in our ways, the most unreasonable of us should be able to agree that getting used to a more sensible naming convention should be an easier alternative to having to take manual action after the fact every time a new file is added to a dataset.

Whatever...

@jjantell: I can't imagine a reason why you'd be seeing what you're seeing. It might just be a column refresh thing though? If you hit to refresh the lister - do you see the values populate for the files that appear to have been missed?

About setting the sort to the Description column. I wouldn't imagine that you want to do that in a button that sets the description.. .since that's something you'd probably only want to run infrequently. I rather imagine you'd want something independent from a button that sets the Description value. If the users who need this sorting have static folder paths where they need to sort on Description, then you could save the sorting in a folder format for either the specific folder paths in scope - or using a wildcard pattern format if you have some unique folder names somewhere in the path to these folders. You could also set a content type folder format... which, if the folders that you'd need this sorting primarily contain PDF files only - you create a content type format for some high percentage of PDF files that would trigger the sort on Description. Shout if you want help figuring out what that means...

[quote="steje"] I can't imagine a reason why you'd be seeing what you're seeing. It might just be a column refresh thing though? If you hit to refresh the lister - do you see the values populate for the files that appear to have been missed?

About setting the sort to the Description column. I wouldn't imagine that you want to do that in a button that sets the description.. .[/quote]

Just to be clear: it is not just the script ending but the whole Opus program ends with no error message.

when you restart OPus only some of the files are populated.

With regard to setting the sort to the Description column, I would like to make the button as user-friendly as possible so that users only need to know that if they press the button the files will sort on date. That may mean setting sort more often than you need but that doesn't do any harm.

On further reflection, I think you are right about sorting the Description field. You don't want to repopulate unnecessarily every time you open a folder whose contents have not changed just to get the sorting set, so necessarily the user will be saving the folder format with e.g. Folder Options and this doesn't need to be done in the button.

So the button does what we want...

...apart from the fact that DOpus terminates part way through.

I have done some more testing and the problem with DOpus ending part way through executing of the script seems only to occur in some rather odd circumstances.

It happens to a folder of PDFs extracted from a ZIP file.

However if, after extracting the folder, you rename the folder, you can run the script with no problem.

More curious still, if you rename the folder, and then rename it back to its original name, you can run the script with no problem.

So I guess the script itself must be fine and it is just some oddity in the latest DOpus beta which causes DOpus itself to end in some unusual circumstances.

I don't now think the problem is anything to do with folder names as it seems to be happening now fairly randomly.

Usually DOpus simple ends with no error message but I have just had it end with a "Windows has detected an error" message.

How can I find out more? In there a control panel option in Windows 8.1 to display details of recent failures?

Is a crash dump created?

The is no crash dump for today though there is one for Monday. Do you want me to PM that to you? Of course that one might have been for some different problem.

I have tried the script on Windows 7 using DOpus 10.5.3.0 and it works fine. I cannot get it to break.

So I am assuming that the script itself is likely to be OK and that the problems under Windows 8.1 are due to Windows 8.1 (or to the way DOpus operates under Windows 8.1).

@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?