Home > Mobile >  bat to generate m3u files in multiple folders excluding specific extension
bat to generate m3u files in multiple folders excluding specific extension

Time:03-17

I have the following bat file which will look at each subfolder in my directory and create an m3u file which lists the contents of that subfolder:

@echo off

for /d %%A in (*) do @if exist "%%~A\*" (
    for %%B in ("%%~A\*") do @echo %%~nxB
) > "%%~A\%%~nxA.m3u"

example: My directory called Names has subfolders Paul, Tom, Susan. Paul has files a.txt, b.txt Tom has files c.txt, d.txt Susan has files e.txt, f.txt

The bat file, in the Names directory runs. It will create:

  • a Paul.m3u file inside the Paul subfolder
  • a Tom.m3u file inside the Tom subfolder
  • a Susan.m3u file inside the Susan subfolder

Each of the m3u files will list that subfolder's files, one file per line.

The problem I am having is that the m3u file is ALSO listing the m3u files itself. I don't want that.

Current output:

a.txt
b.txt
Paul.m3u

Wanted output:

a.txt
b.txt

I recognize that the issue lies in my loop which isn't excluding the .m3u file extension but I'm not sure how to accomplish that. Any pointers?

CodePudding user response:

for %%B in ("%%~A\*") do if "%%~nxB" neq "%%~nxA.m3u" @echo %%~nxB

[untested]

should do what you appear to want, excluding the name.ext part of the .mp3 file being created.

Note that the @s are not required once an @echo off has been executed.

  • Related