是否可以在批处理脚本中使用通配符在路径下捕获所有目录,然后将相关名称用于创建文件
这有点令人费解,我为我的英语差而道歉,这不是我的母语,而且我远没有流利。我希望我当前的代码比我的书面解释更好地解释了我的目标。
@echo off
Setlocal enableextensions enabledelayedexpansion
set BCAT_PATH="C:\\Users\\USER\\Downloads\\FMOD conversion to packable\\0Tools\\bincat"
CD "9temp\\zzz_FSBS_Extract_test"
for /D %%D in (\*) do
"%BCAT_PATH%\\bincat" "%%D\*.ogg" -o "..\\zzz_BuiltOGG_test%%\~ni.tmp"
PAUSE
It's a bit of a convoluted title and I apologise for my poor English, it's not my first language and I'm far from fluent. I hope my current code explains my goal better than my written explanation.
@echo off
Setlocal enableextensions enabledelayedexpansion
set BCAT_PATH="C:\\Users\\USER\\Downloads\\FMOD conversion to packable\\0Tools\\bincat"
CD "9temp\\zzz_FSBS_Extract_test"
for /D %%D in (\*) do
"%BCAT_PATH%\\bincat" "%%D\*.ogg" -o "..\\zzz_BuiltOGG_test%%\~ni.tmp"
PAUSE
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
set "var1=data"
设置字符串值 - 这可以避免尾随空格引起的问题。在比较中;不要分配终端\
、空格或引号 - 从元素构建路径名 - 与直觉相反,它可能会使过程变得更容易。您的
CD
语句将更改为与当前目录相对的目录,因此,如果您当前位于C:\somewhere
到C :\某处\9temp\zzz_FSBS_Extract_test
。如果9temp\zzz_FSBS_Extract_test
是绝对位置,那么您需要\9temp\zzz_FSBS_Extract_test
for /D %%D in (\*) do
会将%%D
设置为根目录中的每个目录名。由于您已更改为..?..9temp\zzz_FSBS_Extract_test
,因此您需要*
来扫描当前目录。您还可以使用"..?..9temp\zzz_FSBS_Extract_test\*"
而不更改目录。 *我不知道9temp\...
在哪里,所以我使用..?..
来表示它的位置。请注意,要执行的命令必须紧跟在
do
之后,位于同一物理行。我添加了ECHO
来显示将执行的命令。验证命令正确后,删除echo
关键字以实际执行该命令。请注意,
BCAT_PATH
设置为C:\Users\USER\Downloads\FMOD 转换为 packable\0Tools\bincat
因此生成的命令将是“C:\Users\USER \Downloads\FMOD 转换为可打包\0Tools\bincat\bincat”。我不知道
%%i
在您的程序中定义。我已将其插入到我认为应该插入的位置。这应该依次将%%i
设置为目录%%D
中的每个.ogg
文件名。%%~ni
应该返回该文件的名称部分。您的输出目录将是
..?..9temp\zzz_BuiltOGG_test
因为您的当前目录是..?..9temp\zzz_FSBS_Extract_test
。\
应放置在目录名和文件名之间。Use
set "var1=data"
for setting string values - this avoids problems caused by trailing spaces. In comparisons; don't assign a terminal\
, space or quotes - build pathnames from the elements - counterintuitively, it is likely to make the process easier.Your
CD
statement will change to a directory RELATIVE to your current directory, so if you are currently atC:\somewhere
toC:\somewhere\9temp\zzz_FSBS_Extract_test
. If9temp\zzz_FSBS_Extract_test
is an absolute location, then you'd need\9temp\zzz_FSBS_Extract_test
for /D %%D in (\*) do
would set%%D
to each directoryname in the root directory. Since you've changed to..?..9temp\zzz_FSBS_Extract_test
, you need*
to scan the current directory. You could also use"..?..9temp\zzz_FSBS_Extract_test\*"
without changing directory. *I don't know where9temp\...
is, so I've used..?..
to represent its location.Note that the command to be executed must follow directly after the
do
, on the same physical line. I've addedECHO
to show the command that would be executed. After you've verified that the command is correct, remove theecho
keyword to actually execute the command.Note that
BCAT_PATH
is set toC:\Users\USER\Downloads\FMOD conversion to packable\0Tools\bincat
The command generated will thus be "C:\Users\USER\Downloads\FMOD conversion to packable\0Tools\bincat\bincat".I've no idea where
%%i
is defined in your program. I've inserted it where I believe it should go. That should set%%i
to each.ogg
filename in the directory%%D
in turn.%%~ni
should return the name part of that file.Your output directory would be
..?..9temp\zzz_BuiltOGG_test
since your current directory is..?..9temp\zzz_FSBS_Extract_test
. The\
should be placed between the directoryname and the filename.虽然
setlocal
是个好主意,但不需要delayedexpansion
。这不会对每个目录执行此操作,而是递归地查找每个
.ogg
文件,然后对每个文件运行该命令。另请注意,我已将.exe
扩展名添加到bincat
There is not need for
delayedexpansion
althoughsetlocal
is a good idea.This will not do for each directory, but instead find each
.ogg
file recursively, then run the command on each file. Also note, I've added the.exe
extension tobincat