![](/img/trans.png)
[英]Create batch file for bulk renaming pdf files in a folder in windows 7
[英]renaming .jpg files in a folder using batch file
我有一個包含bmp文件的文件夾,它們在一個文件夾中可能是4個,在一個文件夾中可能是50個,但是它們是
image.bmp
image1.bmp
image2.bmp
我使用以下代碼啟動了一個批處理文件:
@echo off
setlocal enableDelayedExpansion
SET counter=0
SET /P filename=Please enter the filename:
for %%G in (C:\Test_Folder) do (
ren image*.bmp "%filename%""%counter%".bmp
SET /A counter=%counter%+1;
echo "%counter%"
)
pause
但是計數器沒有增加,有人可以給我的代碼一些啟發嗎?
@echo off
setlocal enableDelayedExpansion
SET counter=0
SET /P filename=Please enter the filename:
for %%G in (C:\Test_Folder\image*.bmp) do (
ren "%%~G" "%filename%!counter!.bmp"
SET /A counter+=1
echo "!counter!"
)
pause
變化:
對counter
變量使用延遲擴展。
for
匹配文件夾中而不是文件夾本身中文件的進程。
使用ren
重命名單個文件,而不使用通配符。
SET /A counter+=1
而不是SET /A counter=!counter!+1
(功能相同,但提高了可讀性)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.