Help creating a Windows 7 batch renaming file

September 6, 2010 at 07:43:23
Specs: Windows 7
Hello

I have a folder (E/Dlpics) which contains various jpg files, certain files have a prefix to them which I would like to remove

ie change

www.somewebsite.org_pic.0101.nikon.jpg

to

pic.0101.nikon.jpg

but if the name of the jpg file does not start with www.somewebsite.org_ then do nothing


I have been unable to write a batch file that works this way, any help greatly appreciated

Cheers

Peter


See More: Help creating a Windows 7 batch renaming file

Report •


#1
September 6, 2010 at 08:17:26
Untested:
for /f "tokens=1,2 delims=_" %%a in ('dir /b www.somewebsite.org_*') do ren "%%a_%%b" "%%b"


Report •

#2
September 6, 2010 at 08:37:01
@echo off & setLocal EnableDELAYedeXpansion

for /f "tokens=* delims= " %%j in ('dir/b www*.jpg') do (
for /f "tokens=2 delims=_" %%a in ("%%j") do (
ren %%j %%a
)
)


=====================================
Helping others achieve escape felicity

M2


Report •

#3
September 6, 2010 at 13:54:18
Thanks guys

Both seem too work as required, you have saved me a lot of time.

Cheers


Report •

Related Solutions


Ask Question