batch - 当前批量处理的文件目录

batch - Directory of the currently processed file in batch

我正在尝试使用解包器来提取多个文件。我的脚本是这样的

for /R %%i in (*.ext) DO quickbms.exe -o script.bms "%%i" "%%~ni"

问题是当我从 C:\archives 删除文件时,它会将所有文件提取到该目录,包括 C:\archives\dir1C:\archives\dir2etc.[= 中的档案15=]

如何将所有存档提取到它们自己的文件夹中,而不必在每个文件夹中手动启动脚本?

for /R %%i in (*.ext) DO quickbms.exe -o script.bms "%%~i" "%%~dpni"

请阅读for /?修饰符可以组合以获得复合结果

来自 Command Line arguments (Parameters):

  • %~f1 Expand %1 to a Fully qualified path name - C:\utils\MyFile.txt
  • %~d1 Expand %1 to a Drive letter only - C:
  • %~p1 Expand %1 to a Path only e.g. \utils\ this includes a trailing \ which will be interpreted as an escape character by some commands.
  • %~n1 Expand %1 to a file Name without file extension C:\utils\MyFile or if only a path is present (with no trailing backslash) - the last folder in that path.

您的 "%%~pi\%%~ni" 将导致(根据上述示例)\utils\MyFile.txt(注意两个连续的 \ reverse solidi)。
幸运的是,批处理解释器将路径中的双重 \(甚至多重)反斜杠视为单个 \ reverse solidus