如何递归列出 Windows .bat 文件中 *.mp3 类型的所有文件?

发布于 2024-09-03 22:14:59 字数 273 浏览 3 评论 0原文

我想递归地列出给定目录中以 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 技术交流群。

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

发布评论

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

评论(2

命比纸薄 2024-09-10 22:14:59

使用命令DIR

dir /s/b *.mp3

上面的命令将搜索当前路径及其所有子路径。要获取有关如何使用此命令的更多信息,请打开命令窗口并键入 DIR /?

Use the command DIR:

dir /s/b *.mp3

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 /?.

我早已燃尽 2024-09-10 22:14:59

下面的批处理文件演示了如何从 for 循环中的变量中提取文件名的元素。将其保存为文件 listfiles.bat,然后运行“listfiles some\folder *.mp3”。

我将文件查找设置为批处理文件中的子例程,以便您可以将其插入到您自己的脚本中。

您还可以运行“for /?”在 cmd shell 中了解有关 for 命令的更多信息。

@echo off
setlocal enableextensions enabledelayedexpansion
call :find-files %1 %2
echo PATHS: %PATHS%
echo NAMES: %NAMES%
goto :eof

:find-files
    set PATHS=
    set NAMES=
    for /r "%~1" %%P in ("%~2") do (
        set PATHS=!PATHS! "%%~fP"
        set NAMES=!NAMES! "%%~nP%%~xP"
    )
goto :eof

The batch file below demonstrates how to extract elements of a filename from the variable in a for loop. Save this as file listfiles.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.

@echo off
setlocal enableextensions enabledelayedexpansion
call :find-files %1 %2
echo PATHS: %PATHS%
echo NAMES: %NAMES%
goto :eof

:find-files
    set PATHS=
    set NAMES=
    for /r "%~1" %%P in ("%~2") do (
        set PATHS=!PATHS! "%%~fP"
        set NAMES=!NAMES! "%%~nP%%~xP"
    )
goto :eof
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文