Prepend the date of the file to the filename

I have a bunch of photos in folders and would like to prepend the filename with the date of the photo. Many of the photos have a "datetaken" in their properties, so I would like to rename those to
YYYY-MM-DD - originalfilename

However, when I use the rename command
{datetaken|yyyy-MM-dd} - *

it turns the P7280001.jpg filename into:
2003-07-28 18;30;36 - P7280001.jpg
whereas I want to turn it into:
2003-07-28 - P7280001.jpg

How can I prevent the time to be included in the name?

To expand this quest a bit further, some files do not have a "datetaken" but do have a "date created" or "date modified" field (I see this in the 'properties' of the files). What I want is to take the earliest date of these three (or of whichever of these three occur in the file) and include prepend the filename with that, again in the YYYY-MM-DD format.
I don't know if this is possible, Is there any way to achieve this elegantly?

thank you,
Roger

How can I prevent the time to be included in the name?

{datetaken|D#yyyy-MM-dd} - *

What I want is to take the earliest date of these three

This needs a script.

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

    var fileItem = getNewNameData.item;
    var itemDateTaken = DOpus.Create.Date(fileItem.metadata.image.datetaken);
    var itemCreate = DOpus.Create.Date(fileItem.create);
    var itemModify = DOpus.Create.Date(fileItem.modify);

    var fileDate = DOpus.Create.Date();

    if (itemDateTaken > 0) fileDate = itemDateTaken;
    if (itemCreate > 0 && itemCreate < fileDate) fileDate = itemCreate;
    if (itemModify > 0 && itemModify < fileDate) fileDate = itemModify;

    tmpStem = fileDate.Format('D#yyyy-MM-dd') + ' - ' + tmpStem;

    return tmpStem + tmpExt;
}

34150.orp (1014 Bytes)

1 Like

That works perfectly! Thanks a lot! Very instructional code too.