Loops Windows批处理:在对每个文件名执行操作时迭代文件名?
当前我的循环读取包含的文件(以.al结尾)。 但是,当我试图设置/更改文件名时,它只会跳转到最后一个文件并使用该文件。(xxx.al) 我已尝试使用EnableDelayedExpansion,但仍无法解决。 最终输出应如下所示Loops Windows批处理:在对每个文件名执行操作时迭代文件名?,loops,batch-file,Loops,Batch File,当前我的循环读取包含的文件(以.al结尾)。 但是,当我试图设置/更改文件名时,它只会跳转到最后一个文件并使用该文件。(xxx.al) 我已尝试使用EnableDelayedExpansion,但仍无法解决。 最终输出应如下所示 spconv -if raw -of wav xxx.al xxx.wav @echo off for %%d in (*.al) do ( set str=%%d set string=%%d:C:\test\test\=% set string2=%string
spconv -if raw -of wav xxx.al xxx.wav
@echo off
for %%d in (*.al) do (
set str=%%d
set string=%%d:C:\test\test\=%
set string2=%string:.al=%
spconv -if raw -of wav %string% %string2%.wav
)
但是,除了xxx.al文件之外,还应该遍历包含的所有文件。i、 e
spconv -if raw -of wav abc.al abc.wav
spconv -if raw -of wav def.al def.wav
当前批处理命令如下所示
spconv -if raw -of wav xxx.al xxx.wav
@echo off
for %%d in (*.al) do (
set str=%%d
set string=%%d:C:\test\test\=%
set string2=%string:.al=%
spconv -if raw -of wav %string% %string2%.wav
)
请参见
获取/?
-尤其是最后一部分。获取/?
在命令行中提供了有关此语法的帮助
此外,替代
变量引用已得到增强。
您现在可以使用以下可选选项
语法:
%~I - expands %I removing any surrounding quotes (")
%~fI - expands %I to a fully qualified path name
%~dI - expands %I to a drive letter only
%~pI - expands %I to a path only
%~nI - expands %I to a file name only
%~xI - expands %I to a file extension only
%~sI - expanded path contains short names only
%~aI - expands %I to file attributes of file
%~tI - expands %I to date/time of file
%~zI - expands %I to size of file
%~$PATH:I - searches the directories listed in the PATH
environment variable and expands %I to the
fully qualified name of the first one found.
If the environment variable name is not
defined or the file is not found by the
search, then this modifier expands to the
empty string
可以组合这些修改器以获得
复合结果:
%~dpI - expands %I to a drive letter and path only
%~nxI - expands %I to a file name and extension only
%~fsI - expands %I to a full path name with short names only
%~dp$PATH:I - searches the directories listed in the PATH
environment variable for %I and expands to the
drive letter and path of the first one found.
%~ftzaI - expands %I to a DIR like output line
在上述示例中,可以使用%I和PATH
将被其他有效值替换。
语法以有效的
用于变量名。拾取大写字母
像%I这样的变量名使它更加
可读性强,避免与
修饰符,它们不是大小写
敏感
您可以使用不同的字母,如f
表示“完整路径名”,d
表示驱动器号,p
表示路径,并且可以将它们组合在一起%~
是这些序列中每个序列的开始,数字I
表示它在参数%I
上工作(其中%0
是批处理文件的完整名称,就像您假设的那样)
在批处理文件中,您应该写入%%I
而不是%I
以转义%%
性格
您的批次看起来如下所示:
@echo off
for %%I in (*.al) do spconv -if raw -of wav %%I %~nI.wav
Pause
谢谢你的帮助!