batch file to check for missing covers

I want to use batch files to check my folders for missing covers and create a playlist of all these folders.

For a simple folder tree with no sub folders

root
-album1
-album2
...

I figured out this code:

@echo off
IF EXIST no_covers.m3u DEL no_covers.m3u
FOR /D %%A IN (*.*) DO (
IF NOT EXIST %%~fA\folder.jpg echo %%~fA%>>no_covers.m3u)

Now I need a batch file that searches all sub folders and only checks for folder.jpg files in folders that also contain audio files because I also have some empty folders in the folder tree.

root
-artist1
---album1
-artist2
--album1
--album2

Can anyone help?

Maybe you could use FOR /R (recursive) loop?
But the tricky thing will be the combination with audio files :huh:

Anyway no mighty help, but maybe a direction to go ...

@ECHO OFF
SET ROOT=M:\MUSIC
SETLOCAL DisableDelayedExpansion

FOR /F "usebackq tokens=*" %%D IN (`DIR "%ROOT%" /B/AD/S/-P`) DO (
   @ECHO."%%D"
   DIR "%%D" /B/A/-P >NUL. 2>&1
   IF ERRORLEVEL 1 (
      ECHO ###Folder "%%D" is empty
   )
)

SETLOCAL DisableDelayedExpansion
... is set, because a foldername with an exclamation mark "!" otherwise is not recognized.

Foldername "Fehlfarben - 2006 - 26 1⁄2" still cannot be handled and will be reported as empty.
Note: The "⁄" is not a normal slash, but a unicode character (hex:E2 81 84).

DD.20110115.2206.CET

If you like PowerShell, then you may look there:
http://technet.microsoft.com/en-us/library/ff730953.aspx
http://technet.microsoft.com/en-us/library/ee692944.aspx

Dano, see attached command file.
Attachment 3574 not found.
DD.2011011.1346.CET

Edit. Attachment removed.
DD.20110117.1747.CET

Thanks Detlev.
But I think I sent you in the wrong direction with the empty folders.
Actually I don't need to check for empty folders.
What I need is
check in every folder if there are any mp3 or flac files and if it is true check if folder.jpg is missing

I tried something inside the loop which seems to work to some extent.

DIR "*.mp3" >NUL 2>&1
   IF ERRORLEVEL 1 (
      IF NOT EXIST "%%~fD\\%FS%" echo %%~fD%>>no_covers.m3u
   )

But it gives false positives on empty folders.

And do you know how to set root to the folder where the cmd file is started in?

%0 is the filepath of the cmd file, so ....

@ECHO OFF
ECHO This cmd's filepath:
ECHO %0
ECHO This cmd's home folder:
ECHO %~dp0
ECHO The root folder:
SET ROOT=%~dp0
ECHO %ROOT%
PAUSE

DD.20110116.1810.CET

It would have been easier to solve the problem by using a more handy scripting language.
Dano, see attached command file.
DD.20110116.2135.CET

Sorry, I did forget to include the most important case:
The folder with music files but without folder.jpg.

Attachment 3580 not found.

DD.20110116.2300.CET

Edit. Attachment removed.
DD.20110117.1747.CET

The solution I found:

DIR "%%~fD\*.mp3">NUL 2>&1
    IF NOT ERRORLEVEL 1 (        
      IF NOT EXIST "%%~fD\\%FS%" ECHO %%~fD>>%FM%
   )

About the root folder, I was looking for %CD%
SET ROOT=%CD% is what I use now so I can start it from TC

I was hoping it was solvable with DOS although it seems tricky. I don't know many other scripting languages.

Well thank you for the great help, I will also look at your last cmd file.

Check.Folder.jpg.cmd
New version, see post #7.
batch file to check for missing covers

DD.20110116.2307.CET

Check.Folder.jpg.cmd
New version here.
Hopefully my last approach.
Attachment 3582 not found.
DD.20110117.1040.CET

Edit. Attachment removed.
DD.20110117.1745.CET

Very nice again, one thing. These vars need quotes:
SET RFA=%HF%%RFA%
SET RMN=%HF%%RMN%
SET RPY=%HF%%RPY%
SET RPN=%HF%%RPN%

Also SET MP3TAG= is a problem when %programfiles% contains spaces.

There's something wrong with the unicode conversion.

Thanks for reporting back.

Regarding the usage of codepages and unicode support see also these interesting articles from user Moonbase:
Feature Request: Unicode Support for Export to Batch Files
HowTo: Einfache Text-Liste aller Bands und Alben
Feature Request: Disable "DOS Box" while running a "Tool"?

There is a new code version attached.
Check.Folder.jpg.cmd
Attachment 3589 not found.

DD.20110117.1930.CET

Edit. Attachment removed.
DD.20110118.1609.CET

Somehow all the unicode report files only get þ as BOM so they can't be displayed correctly.

Huh, how that? Sorry for the invonvenience.
I will download the uploaded file for myself and try to detect what happened with the text file.

There is a zip file attached containing the command file.
I have added a notice into the command file how to create BOM characters via keyboard.
Please try this.
Attachment 3590 not found.
Note: It is possible that Avira reports a false alarm for this cmd file in the zip file.
I've just reported the false alarm to Avira.

The same command file in a 7-zip file is ok for Avira.
But sadly the Forum does not allow to upload a 7-zip file.
Proposal: Upload should be opended for .7z files too.

DD.20110118.1514.CET

Edit. Attachment removed.
DD.20110118.1609.CET

The zip version also fails. It had already happened in earlier versions.

I cannot believe this!

Are you able to create these characters with the keyboard numpad on the DOS commandline ?
BOM marker for UTF-16LE:
hex:FF=[Alt]+Numpad 00255=ÿ
hex:FE=[Alt]+Numpad 00254=þ

If not, then there will be some other way to provide a 2-Byte BOM-only file.
I will think over.
What DOS codepage do you use?

There is a new code version attached.
Check.Folder.jpg.cmd
Attachment 3591 not found.

DD.20110118.1608.CET

Edit. Attachment removed.
DD.20110118.1657.CET

Default codepage is 850
Alt+0255/0254 works

When I type chcp 1252 in the DOS box Alt+0255/0254 give different results.

Hmm, yes, indeed. I have made sure that CP 850 is used when creating the BOM helper file.

Here is a new code version attached.
Check.Folder.jpg.cmd
Attachment 3592 not found.
DD.20110118.1657.CET

Edit. Attachment removed.
DD.20110127.1825.CET

Same issue.
Deltev it seems you must do the opposite, use codepage 1252 to create the unicode files.
In cp 850 these chars have different codepoints (maybe that's the reason, I don't really know)
At least it works for me.

Now I know, I should have used a Windows oriented script language from the first step.
Using olde DOS and it's codepages it is more tricky than I have ever expected.
And it seems that you are right that I've mangled the code points and the code pages and what ever more.
I will look into again, but at first I need a break.
Stay tuned.

DD.20110118.1825.CET