PowerToys
PowerToys copied to clipboard
[PowerRename] variable pattern notation for parent folder
📝 Description
Similar to File Creation Date Replace Notation, have a variable pattern notation $PF
(Parent Folder) which can be used in the Replace with:
field to add the parent folder name to the output renamed files.
Example
Current directory
└─ 0
└─ file1.png
└─ 1
└─ file1.png
└─ 2
└─ file1.png
└─ file2.png
Perform a regex search like : (.*).png
, which captures the filename into variable $1
Replace with: $PF_$1.png
Expected output:
└─ 0
└─ 0_file1.png
└─ 1
└─ 1_file1.png
└─ 2
└─ 2_file1.png
└─ 2_file2.png
If you'd like to see this feature implemented, add a 👍 reaction to this post.
@akulmehta what is the scenario for which this feature is a requirement, instead of just going to the parent folder and start PowerRename from there?
A possible scenario is that maybe the filenames are similar (e.g. above you can see all folders have file1.png
as camera's might be producing these serially in folders) but the folder names are what differentiates the files (above I have just put 0, 1, 2 but they could be specific names which might be for example trip names etc). But rather than having them in a nested folder structure if you want to flatten the directory structure, then you cannot do that as the files would be the same filename. Using PowerRename one could append/prepend the folder name to the file name thereby differentiating the files below.
The point is that if the folder name carries some information which you would like to have in the filename. Currently there is no way to do it except maybe using PowerShell.
@enricogior I am not sure if this answers your question so please let me know if I missed something.
I'd like to do exactly this to put all tracks of music albums in one directory. The tracks are named 01_xxx 02_xxx ... in each folder, so I'd like to prefix them with the parent folder name.
Yes please.
Use case: Parent folders "Theme 1", "Theme 2", "Theme 3"... "Theme 95". Each folder contains 130 icons named "01.ico" "02.ico" ...
Objective: Move all ico files into the same folder, but adjust file names to be meaningfully unique , ie, prefix file names with parent folder name, so I can later move all files to the same folder.
I would also love this as a feature. Especially for music. I usually have a .log and a .cue file in album folders and I want them to be named in a specific way.
Example: Music/Braxton, Anthony/Ninetet (Yoshi's) 1997, Vol. 1 [CD 1]/ -something.log -something.cue Music/Braxton, Anthony/Ninetet (Yoshi's) 1997, Vol. 1 [CD 2]/ -something.log -something.cue
I want them use this syntax: $ParentDir.cue for .cue files and $GrandparentDir - $ParentDir.log for .log files to end up with
Music/Braxton, Anthony/Ninetet (Yoshi's) 1997, Vol. 1 [CD 1]/ -Braxton, Anthony - Ninetet (Yoshi's) 1997, Vol. 1 [CD 1].log -Ninetet (Yoshi's) 1997, Vol. 1 [CD 1].cue Music/Braxton, Anthony/Ninetet (Yoshi's) 1997, Vol. 1 [CD 2]/ -Braxton, Anthony - Ninetet (Yoshi's) 1997, Vol. 1 [CD 2].log -Ninetet (Yoshi's) 1997, Vol. 1 [CD 2].cue
I can achieve this in AdvancedRenamer by using "DirName:1" for .cue files and "DirName:2 - DirName:1" for .log files. But I'd much prefer to be able to do this with PowerRename.
Another example:
subs/a/1_english.srt -> subs/a.srt
subs/b/5_english.srt -> subs/b.srt
subs/c/3_english.srt -> subs/c.srt
Allowing us to capture and match on the entire path that's been opened (i.e. subs/
) would be wonderful, i.e.:
subs\\(.*)\\.*English\.srt -> $1.srt
FWIW, with mmv
on Linux, this would work:
mmv '*/*_English.srt' '#1.srt'
Also, useful on measurement generated files that, as others have pointed out, in general, might be saved with non-unique filenames but folder names or their overall path define the properties or attributes, which for various reasons you might want or need to include in the filenames, and then one can (optionally) move all files to a single directory.
Can we please get this? Was surprised it wasn't already a feature.
How about this: $p3 expands to the 3rd directory above the item, etc.
Current item: 'C:\Users\Bob\Downloads\Cool Band\New album\Track 1.mp3' $p expands to 'Track 1.mp3' (with extension) $p0 expands to '.mp3' (only extension) $p1 expands to 'Track 1' (without extension) $p2 expands to 'New album' $p3 expands to 'Cool Band'
And it completely avoids the problem of them attempting to include path separators in the new name.
So, renaming from '.*' to '$p3 - $p1 ($p2).$p0' would give 'Cool Band - Track 1 (New album).mp3'
what is the scenario for which this feature is a requirement, instead of just going to the parent folder and start PowerRename from there?
You could have many parent folders on the same level, with information you'd rather be in their files' names.
Without it, the alternative is manually repeating the same process, with that information put into PowerRename per folder, on N amount of folders. Could be two, could be five, could be fifty. Wasted time, you know?
For anyone with a similar need for this feature before it's implemented, Advanced Renamer has it.
Over 3 years and still not implemented?
This seems like such a basic string to include too so I'm shocked that it's still not been added.
It would be infinitely useful and from the numerous duplicate requests that have been closed in favour of this one it shows that many other people have a need for this too.
An example:
What we have:
Can't append folder name:
What is required:
Can append each folder name to all the files in its subfolders