递归批量重命名文件扩展名(Windows批处理) [英] Mass rename of file extensions recursively (windows batch)

查看:490
本文介绍了递归批量重命名文件扩展名(Windows批处理)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个非常复杂的目录结构中有许多文件,出于不值得讨论的原因,我需要将所有扩展名为".inp"的文件重命名为具有".TXT"扩展名.我不希望碰到许多其他带有其他扩展名的文件,并且我希望将其递归地压缩到至少5个级别.

I have numerous files in a very complex directory structure, and for reasons not worth discussing I need to rename all files with the extension of ".inp" to have ".TXT" extensions. There are numerous other files with other extensions that I do not want to be touched, and I want to do it recursively down at least 5 levels.

到目前为止,我有:

for /d %%x in (*) do pushd %%x & Ren *.inp *.TXT & popd

...但是这仅会下降一级目录.

...but this only goes down one level of directories.

任何人都可以帮忙吗?预先感谢!

Can anyone help? Thanks in advance!

推荐答案

for /r startdir %%i in (*.inp) do ECHO ren "%%i" "%%~ni.txt"

应该为您工作.将startdir替换为您的起始目录名,当您选中它可以使您满意时,请在ren之前删除echo来真正进行重命名.

should work for you. Replace startdir with your starting directoryname and when you've checked this works to your satisfaction, remove the echo before the ren to actually do the rename.

对于下降投票者:执行批处理文件与从命令提示符中执行命令不同,因为每个%%x其中x是元变量(循环控制变量),都需要减小为%,所以

For the downvoters: executing a batch file differs from excuting from the command prompt in that each %%x where x is the metavariable (loop-control variable) needs to be reduced to %, so

for /r startdir %i in (*.inp) do ECHO ren "%i" "%~ni.txt"

如果从提示符处执行

应该可以.请阅读有关echo的注释.

should work if you execute this from the prompt. Please read the note about echo.

这篇关于递归批量重命名文件扩展名(Windows批处理)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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