hi dostips batch scriptwriter.
what is the batch scripts that add suffix "_001" to all the files with the same file types ".doc" in a specified folder!
for example;
c:\documents\office\jan.doc
c:\documents\office\feb.pdf
c:\documents\office\mar.doc
c:\documents\office\apr.doc
add suffix "_001", "_002", "_003", etc..
as shown below;
c:\documents\office\jan_001.doc
c:\documents\office\feb.pdf
c:\documents\office\mar_002.doc
c:\documents\office\apr_003.doc
thanks
add suffix on files with similar file types!
Moderator: DosItHelp
-
- Expert
- Posts: 391
- Joined: 19 Mar 2009 08:47
- Location: Iowa
Re: add suffix on files with similar file types!
It'll be much easier if you can start with _100 and count up instead of _001, otherwise you have to pad the leading zeros.
*untested*
*untested*
Code: Select all
set /a idx=100
for %%a in (*.doc) do call :process "%%~a"
goto :eof
:process
ren "%~1" "%~n1_%idx%%~x1"
set /a idx+=1
goto :eof
Re: add suffix on files with similar file types!
Code: Select all
setlocal enableextensions
set /a idx=1
for /f "delims=" %%a in ('dir /b/s /a-d /od /tc *.doc') do call :process "%%~a"
goto :eof
:process
set "idx00=00%idx%"
set "idx00=%idx00:~-3%"
ren "%~1" "%~n1_%idx00%%~x1"
set /a idx+=1
goto :eof