批量搜索和替换文件夹名称 [英] batch search and replace folders names
问题描述
我使用批处理文件(命名为folder.bat)来添加字符串_v0_1为我的文件夹下的每个foler名(我在我的文件夹约100文件夹)
我是从包含该行(例如)onother批处理文件调用我的批处理(folder.bat)
通话文件夹arbiter_logic
通话文件夹arbiter_logic_old
块引用>问题,就是批量重命名文件夹也当文件夹名比变量名(%1)时间更长,我想避免它。
我想,如果有变量%1,文件夹名称之间精确匹配的重命名操作将只执行。这里是我的code:
SETLOCAL enabledelayedexpansion
PUSHD G:\\我的文件夹
FOR / F令牌= * delims =%%一个在('DIR / B /广告')做(
集合X = %%一
设置Y = X%1!=%1_v0_1!
仁!到X! !Y!
)
:: ==
光盘..目前不需要的结果是:
arbiter_logic_v0_1
arbiter_logic_v0_1_old_v0_1
块引用>和有用的结果是,批次将改变的文件夹名称,如下所示:
arbiter_logic_v0_1
arbiter_logic_old_v0_1
块引用>我假设有必要应用搜索和文件夹名称内更换的方法,但我不知道怎么做。
VB脚本也将是一个合适的解决方案,如果批处理文件是不行的。
在此先感谢。吉文。
解决方案有没有必要为你的folder.bat。你可以简单的主脚本中重命名的目录。
仁G:\\我的文件夹\\ arbiter_logicarbiter_logic_v0_1
仁G:\\我的文件夹\\ arbiter_logic_oldarbiter_logic_old_v0_1您可以通过使用一个FOR循环节省一些打字,尤其是如果你有很多改名做
为%% f由于(
arbiter_logic
arbiter_logic_old
)做仁G:\\我的文件夹\\ %%〜F%%〜F_v0_1如果您的真正的希望主脚本中调用folder.bat,那么你的folder.bat可以像那样简单。
@renG:\\我的文件夹\\%〜1%〜1_v0_1
i'm using batch file (named as folder.bat) to add the string "_v0_1" for each foler name under "my folder" (i have about 100 folders under "my folder")
I'm calling my batch (folder.bat) from a onother batch file that contains this rows(for example):
call folder arbiter_logic
call folder arbiter_logic_old
the problem, is that the batch rename folders also when the folder name is longer than the variable name (%1) and i want to avoid it .
I want that the renaming action will execute only if there is exact match between variable %1 and the folder name. Here's my code:
setlocal enabledelayedexpansion pushd G:\my folder for /f "tokens=* delims= " %%a in ('dir /b/ad') do ( set x=%%a set y=!x:%1=%1_v0_1! ren !x! !y! ) ::== cd..
currently the unwanted result is:
arbiter_logic_v0_1
arbiter_logic_v0_1_old_v0_1
and the wanted result is that the batch will change the folders name as shown below:
arbiter_logic_v0_1
arbiter_logic_old_v0_1
I'm assuming that there is a need to apply search and replace method within folders names, but i'm not sure how to do so.
vb script will also be a suitable solution if batch file won't do.
Thanks in advance. shay.
解决方案There is no need for your "folder.bat". You can simply rename the directories within your main script.
ren "g:\my folder\arbiter_logic" "arbiter_logic_v0_1" ren "g:\my folder\arbiter_logic_old" "arbiter_logic_old_v0_1"
You can save some typing by using a FOR loop, especially if you have many renames to do
for %%F in ( "arbiter_logic" "arbiter_logic_old" ) do ren "g:\my folder\%%~F" "%%~F_v0_1"
If you really want to call folder.bat within your main script, then your "folder.bat" can be as simple as.
@ren "g:\my folder\%~1" "%~1_v0_1"
这篇关于批量搜索和替换文件夹名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!