Rename Month Name to Month Integer, Rearrange and Cleanup Dates

Hello!

I know there is a script created by MrC called Dynamic Renamer that appears to be able to do this but I'd rather not have to install anything extra to get this functionality. Can this be done using JScript or VBScript and just ran from a button?

I'm not only looking to change, for example; 'Jan' to '01', but also add a leading '0' for Days 1-9, move the Year to the front of the name and add dashes as the separator. Example files names:

Name Here - (Jun 7, 1999) 95 Apples - 10 Oranges.txt
Name Two Here - (Jan 1, 2020) Random 412 Bananas.txt
One More Name - (Dec 25, 2023) Random - Apple - Inserted, Here 1.txt

The parts that need changing:

(Jun 7, 1999)
(Jan 1, 2020)
(Dec 25, 2023)

Would be come:

(1999-07-07)
(2020-01-01)
(2023-12-25)

I'd greatly appreciate any help!

I think this does everything:

Rename preset:

Alternatively, open the Rename dialog, click Edit Script, and paste this in:

function OnGetNewName(getNewNameData)
{
	var name = getNewNameData.newname_stem_m;
	var ext = getNewNameData.newname_ext_m;

	var re = /(^.*\()([A-Za-z]{3} \d{1,2}, \d{4})(\).*$)/;

	var dateStr = name.replace(re, "$2");
	if (dateStr == name)
		return true; // Skip this file.
	var before = name.replace(re, "$1");
	var after = name.replace(re, "$3");

	var date = new Date(Date.parse(dateStr));
	if (isNaN(date))
		return true; // Skip this file.

	var y = date.getFullYear();
	var m = date.getMonth()+1;
	var d = date.getDate();

	dateStr = ZeroPad(y,4) + "-" + ZeroPad(m,2) + "-" + ZeroPad(d,2);

	res = before + dateStr + after + ext;
	return res;
}

function ZeroPad(s,c)
{
	s = s + "";
	while(s.length < c)
	{
		s = "0" + s;
	}
	return s;
}
4 Likes

Works perfectly! Thank you, Leo, for taking the time out of your busy to day to help me with this! Going to save me a ton of time using this :grinning: :+1:

1 Like