Keeping chronological order of folders with deviant "created" time

Here's what i tried, but nothing happens.

Option Explicit
Function OnClick(ByRef clickData)
	Dim strDateTime, strCommand, selItem, re, cmd

	Set re = new RegExp
	re.IgnoreCase = True
	re.Global = False
	' Name, ignoring extension, should be something like "2011-07-29_082609"
	re.Pattern = "^(\d\d)-(\d\d)-(\d\d)"

	Set cmd = clickData.func.command
	cmd.ClearFiles

	For Each selItem in clickData.func.sourcetab.selected
		If (re.Test(selItem.name_stem_m)) Then
			' Set strDateTime to a string like "2011-07-29 08:26:09"
			strDateTime = re.Replace(selItem.name_stem_m, "20$3-$2-$1")
			' DOpus.Output "DT  = " & strDateTime
			strCommand = "SetAttr FILE=""" & selItem.RealPath & """ MODIFIED=""" & strDateTime & """"
			' DOpus.Output "CMD = " & strCommand
			cmd.RunCommand strCommand
		End If
	Next
End Function

What's an example folder name?

The ^ at the start of the regex means it will only match if the date is at the start of the string, which you might not want.

As in the screenshot. The green squares are the correct dates, which i want to transfer to the red squares (which is Erstellt=Created).

What exactly is the string? In "18-Aug-20" is actually is the start of the string, ain't it?

Here is a better screenshot. The left side is meant to be in chronological order, the right side is the one which has the wrong "created" stamps (in my example it is a bit exaggerated, though).

but nothing happens.

You need to convert the month names to numbers, either before running the script or in the script.

Is your goal to manipulate the folders' metadata to get the right sorting order? That will never work properly. The only way is to rename the folders into a sortable (ISO) format. The best way to do this is a Rename script.

function OnGetNewName(getNewNameData) {
    var tmpStem = getNewNameData.newname_stem;
    var tmpExt = getNewNameData.newname_ext;

    tmpStem = tmpStem.replace(/(january|januar|jan)/gi, '01');
    tmpStem = tmpStem.replace(/(february|februar|feb)/gi, '02');
    tmpStem = tmpStem.replace(/(march|märz|maerz|mar)/gi, '03');
    tmpStem = tmpStem.replace(/(april|apr)/gi, '04');
    tmpStem = tmpStem.replace(/(may|mai)/gi, '05');
    tmpStem = tmpStem.replace(/(june|juni|jun)/gi, '06');
    tmpStem = tmpStem.replace(/(july|juli|jul)/gi, '07');
    tmpStem = tmpStem.replace(/(august|aug)/gi, '08');
    tmpStem = tmpStem.replace(/(september|sep)/gi, '09');
    tmpStem = tmpStem.replace(/(october|oktober|oct|okt)/gi, '10');
    tmpStem = tmpStem.replace(/(november|nov)/gi, '11');
    tmpStem = tmpStem.replace(/(december|dezember|dec|dez)/gi, '12');

    tmpStem = tmpStem.replace(/(\d\d)-(\d\d)-(\d\d)/gi, '20$3-$2-$1');

    return tmpStem + tmpExt;
}

36439.orp (1.3 KB)

2 Likes

Sorry, i have no idea how to install the script into the rename section. What is an orp file?

Thanks, i'm also investigating. I actually did not use that rename panel for many years, only my customized MP3 renaming tool bar, so i forgot a lot of stuff. Now i have found how to import the orp intoo the extended rename section. I will make a test run on some copies of my photo folders.

I think it would work with the Created timestamp. AFAIK that won't normally be changed. (Using the Modified timestamp instead would be a bad idea though, on folders.)

Yes, folders seem to be a special case. I will run the test now, let's see.

Hmm, nothing happened. I was expecting the created dates to change. Edit, no wonder, i still could't install the js.

Yes. And actually... you should do it. You kinda deserve it.

:frowning:
I have copied the js script into the field, but it won't let me safe it. Either i abandon it, or i can't click "ok". Sorry for not understanding all this stuff. Thanks for trying to help me.

Here is the picture. Why can't i save this?

Ok, don't bother. I give up. And that's it for me in this forum so far.

Saving rename presets is done via the buttons above the presets list, at the top left of the dialog.

https://www.gpsoft.com.au/help/opus12/index.html#!Documents/Rename_Presets.htm