用于重命名多个文件的cmd命令

时间:2013-12-17 10:48:22

标签: cmd

我在文件夹中有许多文件格式filefirst_131202.txt,只有下划线更改后的数字。

我想将文件重命名为filefirst_us_131202.txt。即,为该文件夹中的所有文件添加“_us”。

尝试执行以下命令,但它不起作用。任何人都可以帮忙..

ren filefirst_*.txt filefirst_us_*.txt
expected Output : filefirst_us_131202.txt 
                  filefirst_us_131203.txt

执行命令后的实际输出为:

filefirst_us_202.txt 
filefirst_us_203.txt 

1 个答案:

答案 0 :(得分:0)

这假设文件名中只有一个下划线:

@echo off
for /f "tokens=1,* delims=_" %%a in ('dir *_*.txt /b ') do ren "%%a_%%b" "%%a_us_%%b"