Hello - new to forum - want to parse file name to variables

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
alanb
Posts: 2
Joined: 14 May 2013 14:21

Hello - new to forum - want to parse file name to variables

#1 Post by alanb » 14 May 2013 14:36

I receive useless DOS file names from outside systems. I need to parse the file name into variables and then rename the file with a usefule name.

EXAMPLE: useless filename 982537.a.null.1.a.tif

DESIRE TO RENAME: usable filename 982537.1.a.tif

ASSUME (but cannot remember how) I can parse into a.b.c.d.e.f into a variable then rename into a.d.e.f form

Thanks !

Glad to find this forum - DOS still kicks buttocks !

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: Hello - new to forum - want to parse file name to variab

#2 Post by Endoro » 14 May 2013 14:47

try this

Code: Select all

set "filename=982537.a.null.1.a.tif"
for /f "tokens=1-6delims=." %%a in ("%filename%") do rename "%%a.%%b.%%c.%%d.%%e.%%f" "%%a.%%d.%%e.%%f"

alanb
Posts: 2
Joined: 14 May 2013 14:21

Re: Hello - new to forum - want to parse file name to variab

#3 Post by alanb » 14 May 2013 15:50

:) Thanks Endoro ! Now I will try to do this for all filenames in a folder....

I appreciate your help !

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: Hello - new to forum - want to parse file name to variab

#4 Post by Endoro » 15 May 2013 01:12

you can simply add an additional for loop:

Code: Select all

cd /d "x:\my picture folder"
for /f "delims=" %%i in ('dir /a-d /b *.tif') do for /f "tokens=1-6delims=." %%a in ("%%~nxi") do rename "%%a.%%b.%%c.%%d.%%e.%%f" "%%a.%%d.%%e.%%f"

Post Reply