Renaming file from the substring of the filename...

  • Thread starter Thread starter Yasutaka Ito
  • Start date Start date
Y

Yasutaka Ito

Hi,

I have bunch of files that are in the form "<filename>_new.htm"... and I wan
to strip the "_new" from the filename.

I was taking a look at For dos command, but can anyone please help this
moron?

thanks!
-Yasutaka
 
Hi,

I have bunch of files that are in the form "<filename>_new.htm"... and I wan
to strip the "_new" from the filename.

I was taking a look at For dos command, but can anyone please help this
moron?

thanks!
-Yasutaka

setlocal
cd /d c:\folder
for /f "Tokens=*" %%s in ('dir /b *_new.htm') set file=%%s&call :rename
endlocal
goto :EOF
:rename
set newname=%file:_new=%
rename %file% %newname%


Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com
 
Jerold said:
setlocal
cd /d c:\folder
for /f "Tokens=*" %%s in ('dir /b *_new.htm') set file=%%s&call :rename

Somehow the do got lost :(
for /f "Tokens=*" %%s in ('dir /b *_new.htm') do set file=%%s&call :rename
endlocal
goto :EOF
:rename
set newname=%file:_new=%
rename %file% %newname%

Hello Jerold,
without having seen this, I just posted a similar solution using delayed
expansion in ambnt.

@echo off & setlocal EnableExtensions ENableDelayedExpansion
for /F "tokens=*" %%A in ('dir /B /A-D test_*.*') do (
set N_=%%A
ren "%%A" "!N_:test_=!"
)
 
Back
Top