tags:

views:

21

answers:

1

I have a Windows batch file utilized in my Visual Studio tool chain that creates a list of files in a particular directory, and then uses "findstr" to narrow this list down to only the files whose names contain a particular string; and then does some work on these files.

dir /b \mypath*.wav >wavRawList.txt

findstr /b /v "DesiredString" wavRawList.txt >wavListWithDesiredString.txt

for /f %%a in (wavListWithDesiredString.txt) do (

[... do some stuff ...]

)

Visual Studio frequently reports errors from this batch file, and I think it's because wavListWithDesiredString.txt frequently ends up being a file with a length of 0. Is there a variety of "if exist wavListWithDesiredString.txt" where instead of "exist" I can substitute a command meaning "if it exists and its file length is greater than 0"?

A: 

The more-or-less inline way, using for:

for %%x in (wavListWithDesiredString.txt) do if not %%~zx==0 (
    ...
)

or you can use a subroutine:

:size
set SIZE=%~z1
goto :eof

which you can call like this:

call :size wavListWithDesiredString.txt
if not %SIZE%==0 ...
Joey