Rename with Metadata but using only parts of it

Hi,

Is it possible to use only parts of the metadata when renaming files (something like {parent2|from|to}) easily (I mean without scripting)?

I've got files in folders three levels deep with parents of various name length
examples:
parent3\01 - parent2\003 - short\file1.ext
parent3\01 - parent2\004 - a bit longer\file2.ext
parent3\02 - longer parent2\001 - arbitrary length\file1234.ext

I have to rename the files to always use the numbers and cut off the rest of the gibberish in the name so that the end results look like:
parent3\01\003\parent3.01.003__file1.ext
parent3\01\004\parent3.01.004__file2.ext
parent3\02\001\parent3.02.001__file1234.ext

Not completely without scripting, but with just a little bit:

// https://resource.dopus.com/t/rename-with-metadata-but-using-only-parts-of-it/31984

function OnGetNewName(getNewNameData) {
    var tmp = String(getNewNameData.item.realpath);
    tmp = tmp.replace(/(.*)\\(.*?)\\(\d\d).*\\(\d\d\d).*\\(.*)/gi, '$1\\$2\\$3\\$4\\$2.$3.$4__$5');
    return tmp;
}

As a preset:

31984.orp (573 Bytes)

2 Likes

Thanks, @lxp, that's intriguing. Is it possible to add numbering to that?

Right now I'm doing that in multiple passes.
First I rename/move everything in its corresponding location (based some part of the name).
Then I add the number to the front of the file name (I have to do that after moving them into folders as the numbering restarts in each folder.
And finally, I remove the unnecessary parts added by {parent n} manually. That manual part was the one I was trying to get rid of. Also, it meant renaming the files three times consecutively. But it seems that scripting could do that in one pass. I'm just inept at scripting. Or rather a complete crap, to be honest :slightly_frowning_face:

Is it possible to add numbering to that?

In general, yes

as the numbering restarts in each folder

That might be a bit of a challenge

Could you post some before/after examples so it becomes clear want you want to achieve?

The file numbering option built into the rename dialog can start a new count for each folder when renaming files in subfolders.

Yes, I accidentally discovered that. That's why I rename the files from one level above, by selecting their folder instead of going into flatview and selecting the files themselves.

Sure, I'll post some real-life examples. I've also noticed that my original examples were incorrect.

The files in those folders are used for deploying database versions using an app called flywaydb. It takes files in said folders (any depth) and only needs the prefix, version, and the delimiter to be properly set. flywaydb accepts a.b.c... (where a, b, and c are arbitrary numbers). The default delimiter is __ (two underscores). The project where this database is used is PRJ, so let's say the prefix is PRJ_V. There will be 3 databases used, so there will be three folders under PRJ_V (only one in the examples). Each database will have several types of object designed, so there will be thousands of files. To organize them, they're sorted into multiple folders under each database folder. Initially, those files have no numbers just their names.

As flywaydb allows no two files with the same version, hence I have to number the files under each folder first.

I've attached a zip with the initial files + folders and end results after rename. Currently I'm able to achieve the results in two passes after the files are already in their corresponding folders. The first one adds numbering to the front of the files. The second one uses a slightly modified version of the script you provided (to avoid removing the descriptive parts of the folders and rename the files in-place instead of moving them).

initial and result.zip (27.7 KB)

Looks doable :slight_smile:

Here's a quick demo how counters can be used in rename scripts:

var counterA = 0;

function OnGetNewName(getNewNameData) {
    counterA++;
    var counterB = getNewNameData.newname_stem;
    tmp = 'A' + counterA + '-' + 'B' + counterB;
    return tmp;
}

31984-8.orp (528 Bytes)