需要协助制作批处理文件以在单独的文件夹中重命名文件


2

好的,这是给你的。我正在尝试使用批处理文件重命名一堆文件,但它们都不与批处理文件本身在同一文件夹中。命令提示符告诉我无法找到该目录。我想我可以重命名与文件名匹配的所有文件夹中的所有文件,但我也不想这样做; 我只想改变某些。

我的批处理文件是:

@echo off
ren "engine/info.txt" "disabled.txt"
ren "gravplating/info.txt" "disabled.txt"
ren "HAWX content/info.txt" "disabled.txt"
ren "laserz/info.txt" "disabled.txt"
ren "NeuroNaval/info.txt" "disabled.txt"
ren "NeuroPlanes/info.txt" "disabled.txt"
ren "NeuroTanks/info.txt" "disabled.txt"
ren "NeuroWeapons/info.txt" "disabled.txt"
ren "WAC Base/info.txt" "disabled.txt"
ren "WAC DamageSystem/info.txt" "disabled.txt"
ren "WAC GravityController/info.txt" "disabled.txt"
ren "WAC Helicopters/info.txt" "disabled.txt"
ren "WAC Sweps/info.txt" "disabled.txt"
ren "weapons/info.txt" "disabled.txt"
ren "AFF_ships/info.txt" "disabled.txt"
ren "AntiTakeRifle/info.txt" "disabled.txt"
ren "Catmull-Rom Cameras/info.txt" "disabled.txt"
ren "Displacer Cannon/info.txt" "disabled.txt"
ren "Drumdevil's Trains/info.txt" "disabled.txt"
ren "EVEOnline/info.txt" "disabled.txt"
ren "gm_botmap_v3/info.txt" "disabled.txt"
ren "gm_construct_flatgrass_v5-2/info.txt" "disabled.txt"
ren "gm_mobenix_v3_final/info.txt" "disabled.txt"
ren "gm_mobenix_v3_highquality_Water/info.txt" "disabled.txt"
ren "gm_snabbansairfield_b1/info.txt" "disabled.txt"
ren "gm_XhS_construct/info.txt" "disabled.txt"
ren "linedraw/info.txt" "disabled.txt"
ren "ModelManipulator/info.txt" "disabled.txt"
ren "NeuroCars/info.txt" "disabled.txt"
ren "Propeller Engine/info.txt" "disabled.txt"
ren "VanDookie and Predaaator's pack/info.txt" "disabled.txt"
ren "WAC ECM/info.txt" "disabled.txt"
ren "WAC Extra Helicopters/info.txt" "disabled.txt"
echo Done!
pause

Answers:


0

你需要考虑两件事:

  1. 您应该使用反斜杠()来分隔路径部件,而不是正斜杠(/)。

  2. 假设您指定的所有目录都与脚本位于同一目录中,并且您从与目录相同的位置运行脚本。

所以,我建议如下更正:

rem CD to the directory in which this script is located:
CD "%~dp0"

rem 'Use' '/', not '\'
ren "gravplating\info.txt" "disabled.txt"
ren "HAWX content\info.txt" "disabled.txt"
ren "laserz\info.txt" "disabled.txt"

rem [...]

除非提问者正在使用其中一个DOS,因为在那里使用非8.3文件名是不可能的,使用正斜杠作为路径名组件分隔符是完全没问题的。CD事实上,至少有一个“批处理文件”可以运行的操作系统在路径名中明确支持它 - 你正在使用该命令假设的操作系统。由于命令参数都是引用而不是绝对路径名,因此不必担心它可能会与命令选项混淆。
JdeBP

JdeBP,我不确定你的意思。我不知道如何在这里写多行注释,所以请阅读: pastebin.com/DkdnVwMs
Yonatan Orlev

呃......嗯?我不完全确定我明白...
Carnaxus

我的答案中有几行。告诉我你到底发生了什么。顺便说一句,任何人都知道如何通过电子邮件通知评论以及给定帖子的答案?
Yonatan Orlev
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.