Reputation: 476
I would like to rename files using batch script.
The files are currently named like this:
pkg_mon_doc_kpps_01.html
pkg_mon_doc_kpps_10.html
pkg_mon_doc_kpps_02.html
And I'd like to change them to:
data_1.xls
data_2.xls
data_3.xls
I made batch file, and when I ran the script, renaming successfully but with a warning
My batch script :
@echo off
set count=0
:: Getting number of files
for %%x in (folder\*.html) do (set /a count+=1)
:: Renaming files
for /l %%a in (1,1,%count%) do (ren folder\*.html data_%%a.xls)
pause
Warning
A duplicate file name exists, or the file cannot be found.
A duplicate file name exists, or the file cannot be found.
A duplicate file name exists, or the file cannot be found.
Press any key to continue . . .
what's wrong? thanks before :)
Upvotes: 0
Views: 3405
Reputation: 605
You must combine your loops:
@echo off
setlocal
set "count=0"
for %%x in (folder\*.html) do (
set /a "count+=1"
call ren "%%x" "data_%%count%%.xls"
)
endlocal
pause
Upvotes: 0
Reputation: 37569
try this:
:: Renaming files
for %%a in (folder\*.html) do (
set /a count+=1
set "fname=%%~a"
setlocal enabledelayedexpansion
ren "!fname!" data_!count!.xls
endlocal
)
and a solution without delayed expansion
:
for /f "tokens=1*delims=:" %%a in ('dir /b /a-d folder\*.html^|findstr /n $') do ren "folder\%%~b" data_%%a.xls
Upvotes: 2
Reputation: 2700
you ask to rename all files in folder at once (ren folder\*.html data_%%a.xls
)
so all *.html are rename to data_1.xls.
you need a loop to rename files one by one.
Upvotes: 0