重命名扩展名为.bak的文件

时间:2015-04-03 17:40:42

标签: batch-file window

我正在尝试重命名具有.bak扩展名的文件。但我不会知道test56.bak名称,因为它一直在变化。

所以我们说:

test56.bak

重命名为:

Upload.bak

我试过这个,但它不起作用:

rename F:\BackupRestore *.bak Upload.bak

1 个答案:

答案 0 :(得分:0)

您使用的

语法不正确

  

REN [drive:] [path] SourceMask TargetMask

正确的语法:

rename F:\BackupRestore\*.bak Upload.bak

用于多个文件

dir c:\bkp\ /A:-D /b | findstr.exe /n /R "*.bkp" > %temp%/file-count.txt

FOR /F "tokens=1-10 delims=:" %%A IN ('type "%temp%/file-count.txt"') do set NUMBER-OF-FILES=%%A

FOR /L %%A IN (1,1,%number-of-files%) DO CALL rename %%A
:rename

FOR /F "tokens=1-10 delims=:" %%A IN ('type "%temp%/file-count.txt" ^| findstr "%1:"') do ren %%B upload-%RANDOM%.bak