循环批量编程 [英] For loop in batch programming

查看:167
本文介绍了循环批量编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 File-MyFile.txt 
File-AnotherFile.txt
File-ThirdFile.txt

我想重新命名下面的所有文件:

 MyFile.txt 
AnotherFile.txt
ThirdFile.txt

如何使用 code>循环来做到这一点?

解决方案

Chris显示了最好的方法。我认为这可能接近你所要求的,但我没有测试它:

  @echo off 
为/ f %% a IN('dir / b * .txt')do call:dorename %% a
goto:eof
$ b $:dorename
set oldfile =% 1
set newfile =%oldfile:File - =%
rename%oldfile%%newfile%


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

File-MyFile.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%

这篇关于循环批量编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆