Trying to rename files using part of a folder name

hello there. i am using opus 12
i have hundreds of folders with multiple files in the folders.
the folders are in the format "20101202 - Christmas Tree 2010"
and the files are in the format "20101202130723.mts"
what i want to do is get the name of the folder after the eight digits and add it after fourteen digits in all the files - "20101202130723 - Christmas Tree 2010.mts"

two questions 1. can i do this within directory opus ? and can i do this on all the folders at once or do they get done one at a time ?

thank you

If you want a button or hotkey which does it:

Rename FROM=* TO=*

@script jscript
function OnGetNewName(getNewNameData)
{
	var name = getNewNameData.newname_stem_m;
	var ext = getNewNameData.newname_ext_m;
	var parentName = getNewNameData.item.path.filepart;
	parentName = parentName.replace(/[0-9]+( - .+)/,'$1');

	return name + parentName + ext;
}

Or if you want a Rename Preset:

Rename Using Part of Parent.orp (501 Bytes)

Both will work on all selected files.


Or you can add RECURSE to the command to make it so you can select one or more folders and have it rename all the files below those folders:

Rename FROM=* TO=* RECURSE

@script jscript
function OnGetNewName(getNewNameData)
{
	var name = getNewNameData.newname_stem_m;
	var ext = getNewNameData.newname_ext_m;
	var parentName = getNewNameData.item.path.filepart;
	parentName = parentName.replace(/[0-9]+( - .+)/,'$1');

	return name + parentName + ext;
}

If using the preset instead, there's a similar checkbox for this in the Rename UI.

Edit: Note that the commands will work on all files/folders at once, ignoring any selection. If you change FROM=* to PATTERN=* it will only work on the selected items (and their children, if RECURSE is also used.)

thank you very much i'll give it a go

works great thank you

2 Likes