I have folder named The Wizard of Oz (199) NEED CHECKING AND CC and is it possible to either rename a file using parentfolder but only get part of the name or make a new subfolder named The Wizard of Oz (1939) using the script to rename a folder or file based upon Parentfolder. Also Diagnosis Murder (1993) - S05E06 - Looks Can Kill NEED CHECKING AND CC to Diagnosis Murder (1993) - S05E06 - Looks Can Kill. I am using the Parentfolder rename to rename many files but at the moment I am putting in a subfolder with just the name and is there an easy to way to either name the files from the subfolder with having to delete the extra such as NEED CHECKING AND CC
I'm not sure what you're asking. Can you rephrase that please?
Giving some before & after examples of what you want to do usually helps clarify what you need with questions about renaming.
basically what I am trying to do is copy the folder name but only copy some of it. The Wizard of Oz (1939) NEED CHECKING AND CC would now have a subfolder named The Wizard of Oz (1939) and then use that parent folder to rename the files in it without having NEED CHECKING AND CC from the subfolders parent folder. So when I use the Folder Name in rename the NEED CHECKING AND CC IS NOT PASSED TO THE FILES NAMES
The Wizard of Oz (1939) NEED CHECKING AND CC Folder
The Wizard Oz (1939) sub folder
The Wizard of Oz_001.ts
The Wizard of Oz_002
So I can use the Folder Name_001 rename or Folder Name_002 etc.
I can't be absolutely certain this is what you want (your quesion is vague), but I have found the ability to use the {parent}
folder in the new name to be very useful, however the inability to MODIFY the parent folder as part of the replacement has been a problem.
The script below adds a new FIELD called "Parent Regex" which is used to match the parent folder name. Whatever part of the original '{parent}' which matches the regular expression provided will replace the actual parent in the renamed file.
As you can see I used .*\([0-9]{4}\)
as the pattern. This matches all text up to (and including) 4 digits in parenthesis.
- This means the ACTUAL parent is
The Wizard of Oz (1939) NEED CHECKING AND CC Folder
- The regular expression matches
The Wizard of Oz (1939)
. - Everywhere
{parent}
is used in theNew name
field, it is replaced withThe Wizard of Oz (1939)
instead ofThe Wizard of Oz (1939) NEED CHECKING AND CC Folder
I've personally found this very useful as I have many filenames which need to be renamed to include a portion of the parent directory.
As a side note, if you use regex (..)
group, the LAST group is used in the replacement.
For example,
- Parent folder is
Wizards S01E03 - The road is winding
- Parent expression is
.*S(..)E.. - .*
- The expression matches the whole string, but only the group result
01
is used. - Final result is
{parent}
is replaced with01
. - I then rename all files from
*
toSeason {parent}\*
and they are moved to a folder calledSeason 01
.
I hope this makes sense.
Cheers
function OnGetCustomFields(d) {
d.fields.parent = '';
d.field_labels('parent') = 'Parent Regex';
}
function OnGetNewName(n) {
var parent = n.item.path.filepart + '';
var parent_regex = n.custom.parent;
var newparent;
if (parent_regex && parent_regex != '') {
var p = parent.match(parent_regex);
if (p && p.length) {
newparent = p[p.length - 1];
}
}
var name = n.newname + '';
var pos = 0;
while (newparent && name.indexOf(parent, pos) >= 0) {
name = name.replace(parent, newparent);
pos += newparent.length;
}
return name;
}
The one for movies works great thank you. How would I change it so that it would work for tv shows as well such as Diagnosis Murder (1993) - S05E06 - Looks Can Kill NEED CHECKING AND CC to Diagnosis Murder (1993) - S05E06 - Looks Can Kill.
It's best to give all the examples you need the rename to handle first, not to drip-feed new requirements after each partial solution.
That way what you want is a lot clearer to those trying to help, and they don't waste time making solutions that might end up being thrown away if it turns out that a different approach is needed because of a requirement that was not communicated at the start.
You could try (.*) NEED CHECKING AND CC
as the Parent Regex.
Thank you very much this worked too.