Page 1 of 1

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

Posted: 01 Sep 2017 09:52
by tlm2408
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.

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

Posted: 01 Sep 2017 10:47
by aGerman
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

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

Posted: 01 Sep 2017 15:06
by tlm2408
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.

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

Posted: 01 Sep 2017 15:15
by aGerman
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

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

Posted: 01 Sep 2017 15:19
by tlm2408
That works perfect!!!! Thank you very, very much. You've made my day!