Challenge
Expanding on this post, how can you prefix filenames to include their parent folder names. @dbenham response (see below) is great, but it only prefix' the immediate parent folder's name in filename. No Powershell allowed!
Before:
C:\Photos\cats
fileA.txt
fileB.txt
fileC.txt
After:
C:\Photos\cats
Photos_cats_fileA.txt
Photos_cats_fileB.txt
Photos_cats_fileC.txt
Where the divider "_" can be any character.
Near Solution
@dbenham's code from this post is as follows:
@echo off
pushd "Folder"
for /d %%D in (*) do (
pushd "%%D"
for /r %%F in (*) do (
for %%P in ("%%F\..") do (
ren "%%F" "%%~nxP_%%~nxF"
)
)
popd
)
popd
What it does
C:\Photos\cats
cats_fileA.txt
cats_fileB.txt
cats_fileC.txt
Again, this doesn't include "Photos". How to include?
Pre-emptive thank you!