Renaming file from the substring of the filename...


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
 
Ad

Advertisements

J

Jerold Schulman

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
 
Ad

Advertisements

M

Matthias Tacke

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_=!"
)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top