Help with renaming files

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
Skeeve

Help with renaming files

Post by Skeeve »

Hi guys,

Very often I have to rename files with let's say kinda chaotic names into a more technical and organized format. The rename features of XY seem to be very flexible and versatile, but I still wasn't able to achieve the required results without manual edits.

Here are some examples:

Before -> After

Dungeon 8 New mastered finalized.wav -> Dungeon 008.wav
Battle special version 12 stereo upgraded FIXED.wav -> Battle 012.wav
Intro 1 Preview RAW.wav -> Intro 001.wav

I figured out how to grab the number with a regular expression, but wasn't able to achieve the result with the leading zeros. Is this possible at all? If so, how?

All help is much appreciated.

Thanks,
Kind regards

highend
Posts: 14996
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Help with renaming files

Post by highend »

Only possible via scripting

E.g.:

Code: Select all

    foreach($file, "<get SelectedItemsNames |>") {
        $firstWord = gettoken($file, 1);
        $number = format(gettoken(regexmatches(gpc($file, "base"), "\d+"), 1), "000");
        renameitem($firstWord . " " . $number, $file);
    }
One of my scripts helped you out? Please donate via Paypal

Skeeve

Re: Help with renaming files

Post by Skeeve »

Hi highend,

Many thanks for the script, that's extremely helpful. I should look deeper into the scripting system, seems to be very powerful.

Thanks again for your help, much appreciated!

Post Reply