我正在设置一个基本的目录交换,我打算用它来翻转Grand Theft Auto V的vanilla和修改版本。我正在拍摄的是一个批处理文件,它将命名交换这两个目录,然后告诉我消息框,哪个安装变量位于主目录中。到目前为止,我有一个交换器,至少告诉我交换成功。
@echo off
ren "Grand Theft Auto V" "Grand Theft Auto V_swap"
ren "Grand Theft Auto V_mod" "Grand Theft Auto V"
ren "Grand Theft Auto V_swap" "Grand Theft Auto V_mod"
msg "%username%" "Files successfully swapped!"
我在每个根目录vanilla.txt
和modified.txt
中添加了一个文件,但我不知道如何进一步使用它们的任何一个名称来显示该消息。
如何让消息报告主目录中的文本文件的名称?如果你能告诉我一个更简单的方法,可以获得奖励。
所以你只需要运行一个for循环,假设那些是每个目录root的唯一txt文件:
@echo off
ren "Grand Theft Auto V" "Grand Theft Auto V_swap"
ren "Grand Theft Auto V_mod" "Grand Theft Auto V"
ren "Grand Theft Auto V_swap" "Grand Theft Auto V_mod"
for %%i in ("Grand Theft Auto V\*.txt") do msg %username% %%~ni
但是,如果您在目录中有其他文本文件,我们可以测试他们的名称,或者将您的文件重命名为某个扩展名而不是其他任何地方。即vanilla.ren
和modified.ren
然后简单地做:
要测试名称,只测试名称匹配时的消息:
for %%i in ("Grand Theft Auto V\*.txt") do (
if /i "%%~ni"=="vanilla" msg %username% %%~ni
if /i "%%~ni"=="modified" msg %username% %%~ni
)
或虚拟扩展:
for %%i in ("Grand Theft Auto V\*.ren") do msg %username% %%~ni