List all mp3 and flac files recursively and save to text file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
tlm2408
Posts: 31
Joined: 01 Aug 2017 01:19

List all mp3 and flac files recursively and save to text file

#1 Post by tlm2408 » 01 Sep 2017 09:52

I need a batch file that will recursively list all the .mp3 and .flac files in the folder C:\Audio with the fullpath to a text file.

Eg. C:\Audio\Albums\AC DC\TNT\Tnt.mp3
C:\Audio\Singles\Cold Chisel - Bow River (live).mp3
C:\Audio\Albums\- Various Artists - 100% Hits Volume 13\11 - Collective Soul _ Shine.mp3
There are about 25,000 files. The files could named with any legal file name characters.

I would like the final result to be formatted as below:
{"Title": "Tnt.mp3","Fullpath": "c:/Audio/Albums/AC DC/TNT/Tnt.mp3"},
{"Title": "Cold Chisel - Bow River (live).mp3","Fullpath": "C:/Audio/Singles/Cold Chisel - Bow River (live).mp3"},
{"Title": "11 - Collective Soul _ Shine.mp3","Fullpath": "C:/Audio/Albums/- Various Artists - 100% Hits Volume 13/11 - Collective Soul _ Shine.mp3"},

I have done quite a lot of searching, but can't find anything that will do this.
There are various levels of directories.
I think I have covered everything.
Thank you for any help recieved.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: List all mp3 and flac files recursively and save to text file

#2 Post by aGerman » 01 Sep 2017 10:47

You could use a FOR /R loop.

Code: Select all

@echo off &setlocal
>"list.txt" type nul
for /r "C:\Audio" %%i in (*.mp3 *.flac) do >>"list.txt" echo {"Title": "%%~nxi","Fullpath": "%%~fi"},


Steffen

tlm2408
Posts: 31
Joined: 01 Aug 2017 01:19

Re: List all mp3 and flac files recursively and save to text file

#3 Post by tlm2408 » 01 Sep 2017 15:06

Thank you Steffen, that works well. Only thing, is it hard to change all the back slashes to forward slashes.
Eg. "C:\Audio/Albums\- Various Artists - 100% Hits Volume 13\11 - Collective Soul _ Shine.mp3" should be "C:/Audio/Albums/- Various Artists - 100% Hits Volume 13/11 - Collective Soul _ Shine.mp3"},

Apart from that it works brilliantly.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: List all mp3 and flac files recursively and save to text file

#4 Post by aGerman » 01 Sep 2017 15:15

tlm2408 wrote:is it hard to change all the back slashes to forward slashes
Not at all.

Code: Select all

@echo off &setlocal
>"list.txt" type nul
for /r "C:\Audio" %%i in (*.mp3 *.flac) do (
  set "fname=%%~nxi"
  set "fpath=%%~fi"
  setlocal EnableDelayedExpansion
  >>"list.txt" echo {"Title": "!fname!","Fullpath": "!fpath:\=/!"},
  endlocal
)

Steffen

tlm2408
Posts: 31
Joined: 01 Aug 2017 01:19

Re: List all mp3 and flac files recursively and save to text file

#5 Post by tlm2408 » 01 Sep 2017 15:19

That works perfect!!!! Thank you very, very much. You've made my day!

Post Reply