开发者

For loop in batch programming

开发者 https://www.devze.com 2023-01-25 04:18 出处:网络
I have a set of files in a directory like below: File-MyFi开发者_运维知识库le.txt File-AnotherFile.txt

I have a set of files in a directory like below:

File-MyFi开发者_运维知识库le.txt
File-AnotherFile.txt
File-ThirdFile.txt

I want to rename all files like below:

MyFile.txt
AnotherFile.txt
ThirdFile.txt

How can I use a for loop to do that?


Chris shows the best way to do it. I think this might come close to what you asked for, though I didn't test it:

@echo off
for /f %%a IN ('dir /b *.txt') do call :dorename %%a
goto :eof

:dorename
set oldfile=%1
set newfile=%oldfile:File-=%
rename %oldfile% %newfile%


you don't need a for loop:

rename File- "" File-*.txt
0

精彩评论

暂无评论...
验证码 换一张
取 消