Page 1 of 1
How to Rename folder as great grandparent folder name
Posted: 26 Aug 2021 07:33
by aswinrm
Hello,
I have a dataset which needs to be renamed.
The structurre of folder is as follows.
D:\XXXX\Control\PPMI\3104\MPRAGE_GRAPPA\2011-08-01_13_30_13.0\S120955\######.dcm
S120955 folder needs to changed as 3104 [great grandparent folder name]

Re: How to Rename folder as great grandparent folder name
Posted: 26 Aug 2021 08:19
by highend
Go into the "
D:\XXXX\Control\PPMI" folder (and nowwhere else^^) and execute the script...
You'd better do it with some test data, e.g. by duplicating your original folder(s)...
Rename to grandfather + suffix.xys
Re: How to Rename folder as great grandparent folder name
Posted: 26 Aug 2021 08:22
by RalphM
Hi, welcome to the forum.
Short answer, AFAIK not possible out of the box.
You would need to script this by getting the name of the folder two levels up and then rename the subfolders accordingly.
Edit: Two minutes too slow and there you already got a script done for you.
Re: How to Rename folder as great grandparent folder name
Posted: 26 Aug 2021 09:35
by aswinrm
highend wrote: ↑26 Aug 2021 08:19
Go into the "
D:\XXXX\Control\PPMI" folder (and nowwhere else^^) and execute the script...
You'd better do it with some test data, e.g. by duplicating your original folder(s)...
Rename to grandfather + suffix.xys
Thanks a lot...
Code: Select all
$firstSub = gpc($item, "component", -($cntRootSep +1));
changed the foldername as PPMI_T1 ....
However when i changed it to "+0 " the script worked as needed...
Re: How to Rename folder as great grandparent folder name
Posted: 26 Aug 2021 09:52
by highend
Replace the line with
$firstSub = gpc($item, "component", -($cntSep - $cntRootSep));
then it should work regardless of depth...
I've reuploaded the script as well
Re: How to Rename folder as great grandparent folder name
Posted: 26 Aug 2021 10:03
by aswinrm
highend wrote: ↑26 Aug 2021 09:52
Replace the line with
$firstSub = gpc($item, "component", -($cntSep - $cntRootSep));
then it should work regardless of depth...
I've reuploaded the script as well
Thanks...
Newly uploaded script works perfectly...
