I have a large number of folders each containing a number of text files. The folders have generic names like 'UD' or 'KX'.
I want to add the name of each folder to the start of all filenames of files within the folder.
so files:
filename1
filename2
filename3
in folder KX
should be renamed:
KX_filename1
KX_filename2
KX_filename3
thanks,
mark
Adding folder name to filenames
Moderator: DosItHelp
Re: Adding folder name to filenames
Run this, it will pause after each folder and show you the commands it would use for that folder.
If it looks right then remove the 2nd echo and the pause and rerun it.
If it looks right then remove the 2nd echo and the pause and rerun it.
Code: Select all
@echo off
for /f "delims=" %%a in ('dir /ad /b /s') do (
echo ==="%%a"===
pushd "%%a"
for /f "delims=" %%a in ('dir /a-d /b') do echo ren "%%b" "%%~nxa_%%b"
popd
pause
)