Rename file to match its folder

June 9, 2010 at 16:11:53
Specs: Windows XP, 2.3 3G
Hi all,
I have yet another drama,

So the problem is I have been recieving a high number of *.PDF files for people that do not have the persons name in the file.
i have currently,
Folder (Brown, John)
File (VST123456_ABC.PDF)

I am trying ot achieve a BAT file that can scan all the folders and sub folders in a directory for any *.PDF files and rename the *.PDF to the folder it is in.

What im trying to achieve
Folder (Brown, John)
File (JohnBrownVST123456_ABC.PDF)

So each *.PDF is already placed in the correct folder but the name is not correct.

See More: Rename file to match its folder

Report •

June 9, 2010 at 17:58:56
I am thinking something like,

Search DIR for *.PDF
IF found rename *PDF using Token,1 from DIR

Repeat through each directory

Report •

June 9, 2010 at 19:25:01
Those parentheses are what's gonna drive you nuts. whoever designed the filenames should have to fix his/her idiocies.

Report •

June 9, 2010 at 23:36:33
The following command is one that renames and moves,

@echo off
setlocal enabledelayedexpansion

for /f "delims=" %%A in ('dir /a-d /b /tc "*.PDF"') do (
md "%%~nA"

set file=%%~tA

set file=!file:~6,4!!file:~3,2!!file:~0,2!_!file:~11,2!!file:~-2!.pdf

move "%%A" "%%~nA\!file!"> nul

Can this command not be tweeked to achive my goal?

all i want to do is change the name of a file to match the directory it is in.

If anyone can suggest any good reading material so i can help myself

Report •

Related Solutions

June 10, 2010 at 00:07:14
well, i doubt this will help, but you're welcome to try it:

@echo off & setlocal enabledelayedexpansion
for /f "tokens=*" %%a in ('dir /b /s *.pdf') do (
set test=%%~pa
set test=!test:~0,-1!
for /f "tokens=*" %%b in ("!test!") do set xx=%%~nb
for /f "tokens=1,2 delims=(,) " %%c in ("!xx!") do set yy=%%d%%c
set zz=%%~na
set zz=!yy!!zz:(=!.pdf
echo ren %%a !test!\!zz!

Report •

Ask Question