0

I have a list of files that I'm looking for in a directory. They are all JPG files. I need to know how to return a value which will only look once in the directory. This will be within an existing FOR loop, as the point of the For loop is to actually print out the list of missing files.

Here is a partial code listing:

for %%C in (front back cd artist icon) do  (
            if not exist "%%~B\%%~C.jpg" (
                if %AlbumInfo% == 0 (
                    echo %%~nxA - %%~nxB
                    set AlbumInfo = 1
                )
            echo   Missing: %%C.jpg
            )
        )

So basically, I want to know if any item in (front back CD artist icon) is found in an album directory, and if it is, then print the Album - Artist line once. As it is right now, it prints it out for every missing file, along with the missing file itself. I attempted to use the variable AlbumInfo to assist in this by setting it to 0 or 1. No luck. How can I do this, using the file list names as presented in the code? I can post the entire code if necessary.

Here is Sample Desired Output:

Album - Artist
<list files missing>
Josh
  • 3
  • 4
  • 1
    Does this answer your question? [Variables in batch file not being set when inside IF?](https://superuser.com/questions/78496/variables-in-batch-file-not-being-set-when-inside-if) – T3RR0R Apr 13 '21 at 14:41
  • Not really. I've seen that before. I'm mainly looking to see if any files with the same names that are within the parenthesis are found. Again: (front back CD artist icon), any of those filenames plus a *.jpg" extension. If they are found, print a list, set a variable so the question isn't asked again. until it's out of the loop completely. – Josh Apr 13 '21 at 15:08
  • 1
    you have two problems with your posted code. One is the delayed expansion issue the above link is about. The other is you assign 'AlbumInfo`SPACE`' not 'AlbumInfo'. Use `Set "Albuminfo=1"` – T3RR0R Apr 13 '21 at 15:20
  • Given you've posted an incomplete section of a series of nested for loops, there may well be other issues beyond that – T3RR0R Apr 13 '21 at 15:22
  • 1
    Your comment with respect to Set "AlbumInfo=" fixed it. I also messed around with the If statement as well, using Exclamation marks instead of percent signs. I answered the question and posted the code. Thank you for your assistance. – Josh Apr 13 '21 at 22:15

1 Answers1

0

Final code. See the comments below for the changes.

for %%C in (front back cd artist icon) do  (
            if not exist "%%~B\%%~C.jpg" (
                if !AlbumInfo! == 0 (
                    echo %%~nxA - %%~nxB
                    set /A album += 1
                    set "Albuminfo=1"
                )
            echo   Missing: %%C.jpg
            set /A missing += 1
            )
        )

Two problems and fixes I had with this code:

Setting this:

if %AlbumInfo% == 0 (

To this:

if !AlbumInfo! == 0 (

Setting this:

set Albuminfo=1

To this:

set "Albuminfo=1"
Josh
  • 3
  • 4