用一个批处理文件重新命名递归文件名+文件夹名称 [英] recursive renaming file names + folder names with a batch file
问题描述
我想创建一个批处理文件(操作系统CMD)的递归经过一个选择的文件夹和子文件夹,重命名为有文件夹+具有以下规则:
I like to create a batch file (winxp cmd) that recursively goes through a chose folder and sub folders and renames there files+folders with the following rules:
这所有的文件夹+名,全部大写小写+V和W字母必须以字母Y和Z所取代。
from all file + folder names, all uppercase+lowercase "V" and "W" letters need to be replaced with letters "Y" and "Z".
例如。 11V0W必须成为11Y0Z。
e.g. 11V0W must become 11Y0Z.
我相信它可能与FOR / R但如何?
我觉得这里需要一个子程序调用,除了用FOR / R基本递归一个检查每个字母之一。
I believe its possible with FOR /R but how? I think there needs to be a subroutine to be called that checks each letter one by one in addition to basic recursion with FOR /R.
推荐答案
下面的批处理做到这一点,至少在文件名。目录是有点棘手(至少我不能拿出一个无解的无限至今):
The following batch does this for the file names at least. Directories are a bit trickier (at least I couldn't come up with a non-infinite solution so far):
@echo off
setlocal enableextensions
for /r %%f in (*) do call :process "%%f"
endlocal
goto :eof
:process
pushd "%~dp1"
set fn=%~nx1
set fn=%fn:V=Y%
set fn=%fn:W=Z%
ren "%~nx1" "%fn%"
popd
goto :eof
但在理论上应该不会太难钉DIR重命名到这个。
But in theory it shouldn't be too hard to tack dir renaming onto this.
这篇关于用一个批处理文件重新命名递归文件名+文件夹名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!