如何递归列出 Windows .bat 文件中 *.mp3 类型的所有文件?
我想递归地列出给定目录中以 mp3 结尾的所有文件的绝对路径,该目录应作为相对目录给出。
然后,我还想从文件中删除目录,并且我已经读到 for
范围内的变量必须包含在 !
中。是这样吗?
我当前的代码如下所示:
for /r %%x in (*.mp3) do (
set di=%%x
echo directory !di!
C:\bla.exe %%x !di!
)
I want to recursively list the absolute path to all files that end with mp3
from a given directory which should be given as relative directory.
I would then like to strip also the directory from the file and I have read that variables which are in a for
-scope must be enclosed in !
s. Is that right?
My current code looks like this:
for /r %%x in (*.mp3) do (
set di=%%x
echo directory !di!
C:\bla.exe %%x !di!
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用命令
DIR
:上面的命令将搜索当前路径及其所有子路径。要获取有关如何使用此命令的更多信息,请打开命令窗口并键入
DIR /?
。Use the command
DIR
:The above command will search the current path and all of its children. To get more information on how to use this command, open a command window and type
DIR /?
.下面的批处理文件演示了如何从
for
循环中的变量中提取文件名的元素。将其保存为文件listfiles.bat
,然后运行“listfiles some\folder *.mp3”。我将文件查找设置为批处理文件中的子例程,以便您可以将其插入到您自己的脚本中。
您还可以运行“for /?”在 cmd shell 中了解有关
for
命令的更多信息。The batch file below demonstrates how to extract elements of a filename from the variable in a
for
loop. Save this as filelistfiles.bat
, and run "listfiles some\folder *.mp3".I set up the file finding as a subroutine in the batch file so you can insert it into your own scripts.
You can also run "for /?" in a cmd shell for more information on the
for
command.