Help with button to extract dates and change the created date for the folder

I guess this would be some scripting thing. The underlying issue is, that time stamps of folders are getting messed up, when the folders are copied at some later time to a different machine, sometimes leaving those folders non-chonological.

In that case i have to go to the metadata panel and change them all by hand, which isn't so convenient when having lots of folders to process.

My dates are created in the dd-MMM-yy format in german language (if this matters to the script), so the task would be to fetch that date string and somehow change the folder's created date to this value. As far as i can guess, there is no other way to get the original dates, except from the folder's names, once the time stamp has been changed through copying at some later time.

Does your boss know about this?

Do I sense a bit of masochism here?

Well, save CommandSetTimestampsFromFilenameGerman.js.txt to

%appdata%\GPSoftware\Directory Opus\Script AddIns

Then try SetTimestampsFromFilenameGerman... check the logs... you know the drill, right?

JScript
function OnInit(initData) {
    initData.name = 'SetTimestampsFromFilenameGerman';
    initData.version = '2023-08-17';
    initData.default_enable = true;
    initData.min_version = '12.0';
}

function OnAddCommands(addCmdData) {
    var cmd = addCmdData.AddCommand();
    cmd.name = 'SetTimestampsFromFilenameGerman';
    cmd.method = 'OnSetTimestampsFromFilenameGerman';
    cmd.hide = false;
    cmd.icon = 'script';
}

function OnSetTimestampsFromFilenameGerman(scriptCmdData) {
    var cmd = scriptCmdData.func.command;
    var tab = scriptCmdData.func.sourcetab;

    cmd.deselect = false;

    var map = DOpus.Create().Map();

    map('jan') = '01';
    map('feb') = '02';
    map('mar') = '03';
    map('mär') = '03';
    map('apr') = '04';
    map('mai') = '05';
    map('jun') = '06';
    map('jul') = '07';
    map('aug') = '08';
    map('sep') = '09';
    map('okt') = '10';
    map('nov') = '11';
    map('dez') = '12';

    var re = /.*(\d\d)-(\w\w\w)-(\d\d).*/;

    for (var e = new Enumerator(tab.selected); !e.atEnd(); e.moveNext()) {
        var item = e.item();

        var tmp = item.name.match(re);
        if (tmp == null) continue;
        if (tmp.length != 4) continue;

        var strDate = '20' + tmp[3] + '-' +
            map(tmp[2].toLowerCase()) + '-' +
            tmp[1] +
            ' 00:00:00';

        var cmdLine = 'SetAttr' +
            ' FILE="' + item + '"' +
            ' CREATED="' + strDate + '"' +
            ' MODIFIED="' + strDate + '"';

        DOpus.Output(cmdLine);
        // cmd.RunCommand(cmdLine);
    }
}
2 Likes

What a beautiful script :slight_smile:

Sorry, I don't "know the drill, right? - but I would like to get to know it, please :smiley:

Hmm, that looks promising, lxp. But what is supposed to happen exactly? The created time stamp of the folder stays the same. Or did i miss something? Also, not sure which logs.

Lxp, i found the log now, it was the other one. Looks promising, except i would like to change the created date instead of modified. Is it ok to change

' MODIFIED="' + strDate + '"';

to

' CREATED="' + strDate + '"';

in the 5th last line?

That is already in the previous line :slight_smile:

Don't forget to uncomment :wink:

DOpus.Output(cmdLine);
// cmd.RunCommand(cmdLine);
1 Like

Yep, uncommenting did the trick. Very cool. I can even batch process the folders with your script. If you do this while on your job, i hope your boss doesn't know about it. :wink:

Thanks a lot!

:beers:

Anyone care to point out the "drill"? Please?

Test.

DOpus.Output(cmdLine);
// cmd.RunCommand(cmdLine);

I'm really sorry, but how do I test this?

I guess you can only test it, if you have your folders name in the dd-MMM-yy format AND in the german spelling, which might not be the case, without making some changes to the script.

Just checked your profile, so you can use it, if you're using the german time format like 16-Aug-23.
Suppose, your time stamp is 17-Aug-23, you can use the script, after having placed the script in the Script Addins folder and have uncommented that line (// cmd.RunCommans(cmdLine)). If you then run the SetTimestampsFromFilenameGerman command from the command line or from a button, your created time stamp will be set accordingly to your folder's name.

@abr , thank you for replying. I am so interested in that script, because I recently wrote a "function" (outside of DOpus) transforming various strings into "YYYY-MM-DD" (ISO-format? with RegEx) and will soon be wanting a script within DOpus to transfer

  1. file-names to metadata Title
  2. year to metadata Year

I would really like to learn how to create a script in DOpus. In fact, I would like to also learn how to begin writing a script.

I have what one might call a "Subway Knowledge" of things, like when I moved to Berlin, I knew how to get from A to B, got to know the sourroundings of A and B, and there somewhere was a C. I could reach all these points by subway, but I could not navigate the streets.

I know some HTML, CSS, JavaScript, Regex, and SQL but I struggle to link them together.

I didn't know JScript last year either, but I tested a lot and searched the forum and gradually learned the basics.

Very good, so tell me how I get a first basic script, something like:

myMessage := "Hello World"
alert(myMessage)

Please :smiley:

Itisi, maybe lxp's other script can give you some ideas?

This looks very promising. I will check it. Too late now.

But could someone please tell me how to create this basic script (with the proper commands of course):

myMessage := "Hello World"
alert(myMessage)

And then how to use it in DOpus.

That's how I learned my html, my css. I'll take it from there...
Thank you.

function OnClick(clickData) {
    var dlg = clickData.func.Dlg();
    dlg.title = 'Basic script';
    dlg.message = 'Hello World';
    dlg.buttons = '&OK';
    dlg.show
}
1 Like

Nothing spectacular, just the basic steps. Know how to run a script command, know where to find the logs and how to read them, know how to check if the script will do what you expect it to do, know how to unlock a script (because in its original state, it shoots only blanks for safety).

Thank you all :smiley: @lxp, @abr and @WKen

Nothing spectacular, just the basic steps

Let me try to clarify "the basic steps" (having done some reading)

  1. I write a script (VSCode) and save it with a ".js" extension
  2. I save this script to
    a) %appdata%\GPSoftware\Directory Opus\Script AddIns
    b) %appdata%\Roaming\GPSoftware\Directory Opus\Scripts

Question: Is it a) or b) or either? What is the difference?

  1. Know how to run a script command: link it to a button, menu item

About your script @lxp, what I (later, much later) will try to extract from it is the way you assign values to meta data. (Need to write file-name and year to their respective metadata-fields)

@WKen Your little script will be the seed for all the others. It is straightforward enough to comprehend easily and tinker around with.

@abr your pointing me to "copymeta-copy-metadata-between-files" by @lxp will provide me with the necessary vocabulary

So at last, I will get to know more streets and more connections.

Thank you all very much :smiley:

And here's my favourite quote by Antoine de Saint-Exupéry

The little prince never let go of a question

It's a). b) doesn't exist.

Opus can create the script for you (Preferences / Toolbars / Scripts):