0

I've been doing some archiving of my music library lately. I have finalized my batch script as follows:

@echo off
for /r %%a in (*.mp3) do (
    if exist "%%~dpna.txt" (
        Echo "%%~dpna.txt" already present, skip
    ) else (
       for /f "tokens=1,*delims=-" %%b in ("%%~na") do (
           echo Artist: %%b
           echo Song  :%%c asdad
       )>"%%~dpna.txt"
    )
)

Pretty good so far. Had help in the forum as well. >> Parse file name using batch automation

With this script I was able to accomplish the output by parsing and using the file name. But the problem I face now is, not all my files are not in the same format. So further research for my goal. I decided to accomplish my task by extracting metadata using ffprobe. Code seems fine but I can't seem to echo the result and it's showing echo off. Any help would be much appreciated.

Current code is as follows.

@echo off
for /r %%a in (*.mp3) do (
    if exist "%%~dpna.txt" (
        Echo "%%~dpna.txt" already present, skip
    ) else (
       for /F "delims=" %%I in ('ffprobe -v error -show_entries format_tags^=title,artist,comment -of default^=noprint_wrappers^=1:nokey^=1 %aa') do set "title=%%I"
       )>"%%~dpna.txt"
    )
)
  • 2
    What is `%aa`? _note that your metavariable is **`%%a`** and that any **`%`** characters should be doubled in a batch file_. Also I note that you've escaped your **`=`** characters, but not your **`,`** characters, I'd suggest those are escaped too! I'm assuming too that your `ffprobe` executable is local to the batch file or its location listed in **`%PATH%`**, but you're only `Set`ting the variable, not `Echo`ing it to the text file. – Compo Jun 12 '18 at 11:39
  • What is your question and what is your intended output? – Squashman Jun 12 '18 at 12:48

1 Answers1

0

I see no reason whatsoever for your nested For loop, you should be able to run ffprobe directly because you're not parsing it's output, just redirecting it to a file.

Please try this variation:

@Echo Off
For /R %%A In (*.mp3) Do If Not Exist "%%~dpnA.txt" (
        ffprobe -v error -show_entries format_tags=artist,comment,title -of default=nw=1:nk=1 "%%A"
    )>"%%~dpnA.txt"
Compo
  • 36,585
  • 5
  • 27
  • 39
  • Thanks! This helped a lot. I'm not really a programmer. Just doing what I can from research. Didn't know there was a simpler way to not overwrite existing files. Neat and tidy. GJ. Thanks dude. Cheers! :) – Mr-RightHanded Jun 12 '18 at 13:42