使用批处理文件递归重命名文件名+文件夹名

编程入门 行业动态 更新时间:2024-10-20 16:21:16
本文介绍了使用批处理文件递归重命名文件名+文件夹名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我喜欢创建一个批处理文件(winxp 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

但从理论上讲,将目录重命名添加到此应该不会太难.

But in theory it shouldn't be too hard to tack dir renaming onto this.

更多推荐

使用批处理文件递归重命名文件名+文件夹名

本文发布于:2023-11-28 16:48:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643188.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:递归   文件名   文件夹   重命名   批处理文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!