Grandparent folder (parent of parent)?

Javascript renaming examples. Javascript renaming is supported in version 3 or newer.

Grandparent folder (parent of parent)?

Postby pintocat » Tue Oct 25, 2016 5:37 pm

I have a bunch of files which have the subdirectory structure backwards.

They're like this:


I want to rename the files, prepending the folder names, but I don't want to do it in the order of the heirarchy like the setting of Append Folder Name, Levels (2) will do.

(I don't want it to be Level1Level2Filename). I want it to be Level2Level1Filename.

Is there a way I can get the grandparent/parent of parent to do this in two steps? Or some way to do it in one step?
Posts: 1
Joined: Tue Oct 25, 2016 5:32 pm

Re: Grandparent folder (parent of parent)?

Postby therube » Tue Oct 25, 2016 7:46 pm

Posts: 313
Joined: Mon Jan 18, 2016 6:23 pm

Re: Grandparent folder (parent of parent)?

Postby KenP » Tue Oct 25, 2016 8:06 pm

1. Rename the files prefixing the file names with the 2 levels of folder names.

Append Folder Name (9)
Name: Prefix
Sep: -_-
Levels: 2

2. Rename
3. Reset

4. Use Regex to change the order of the file names

RegEx (1)
Match: (.*)-_-(.*)-_- (.*)
Replace: \2-\1-\3 (I've included hyphens in the replace for clarity, but if you don't want them just leave them out so it becomes (Replace: \2\1\3))
Posts: 193
Joined: Sat Jul 30, 2016 11:25 am

Re: Grandparent folder (parent of parent)?

Postby Admin » Tue Oct 25, 2016 11:36 pm

Just FYI, alternatively this can also be done with a Javascript function (in 1 step).

Code: Select all
var subfolders = object("folder").split("\\");
newName = subfolders[1] + subfolders[2] + name;
Site Admin
Posts: 1464
Joined: Tue Mar 08, 2005 8:39 pm

Return to Javascript Renaming