是否可以在批处理脚本中使用通配符在路径下捕获所有目录,然后将相关名称用于创建文件

发布于 2025-01-18 15:00:51 字数 375 浏览 1 评论 0原文

这有点令人费解,我为我的英语差而道歉,这不是我的母语,而且我远没有流利。我希望我当前的代码比我的书面解释更好地解释了我的目标。

@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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

落墨 2025-01-25 15:00:51
@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 FOR %%i in ("%%D\*.ogg") do ECHO "%BCAT_PATH%\bincat"  "%%i" -o "..\zzz_BuiltOGG_test\%%~ni.tmp"
PAUSE

使用 set "var1=data" 设置字符串值 - 这可以避免尾随空格引起的问题。在比较中;不要分配终端 \、空格或引号 - 从元素构建路径名 - 与直觉相反,它可能会使过程变得更容易。

您的 CD 语句将更改为与当前目录相对的目录,因此,如果您当前位于 C:\somewhereC :\某处\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\ 应放置在目录名和文件名之间。

@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 FOR %%i in ("%%D\*.ogg") do ECHO "%BCAT_PATH%\bincat"  "%%i" -o "..\zzz_BuiltOGG_test\%%~ni.tmp"
PAUSE

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 at C:\somewhere to C:\somewhere\9temp\zzz_FSBS_Extract_test. If 9temp\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 where 9temp\... 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 added ECHO to show the command that would be executed. After you've verified that the command is correct, remove the echo keyword to actually execute the command.

Note that BCAT_PATH is set to C:\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.

桃扇骨 2025-01-25 15:00:51

虽然 setlocal 是个好主意,但不需要 delayedexpansion

这不会对每个目录执行此操作,而是递归地查找每个 .ogg 文件,然后对每个文件运行该命令。另请注意,我已将 .exe 扩展名添加到 bincat

@echo off
setlocal & set "BCAT_PATH=C:\Users\USER\Downloads\FMOD conversion to packable\\0Tools\bincat"
cd /d "9temp\\zzz_FSBS_Extract_test"
for /R %%i in (*.ogg) do "%BCAT_PATH%\bincat.exe" "%%~i" -o "..\zzz_BuiltOGG_test\%%~ni.tmp"

There is not need for delayedexpansion although setlocal 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 to bincat

@echo off
setlocal & set "BCAT_PATH=C:\Users\USER\Downloads\FMOD conversion to packable\\0Tools\bincat"
cd /d "9temp\\zzz_FSBS_Extract_test"
for /R %%i in (*.ogg) do "%BCAT_PATH%\bincat.exe" "%%~i" -o "..\zzz_BuiltOGG_test\%%~ni.tmp"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文