BAT File conditional check for empty string

Dell / M6300
April 29, 2009 at 10:39:23
Specs: Windows XP, 8 GB
I'm having some trouble testing is a txt file is empty in BAT file syntax. I can get it to work properly if I have a string with characters, but not if the variable is an empty string.

For example, this works...
set /p Var1=<queue.txt
if "%Var1%"=="B" (
echo "B is in the file."
exit /b
) ELSE (
echo "Not B."
exit /b
)

But if I try this, it doesn't work...
set /p Var1=<queue.txt
if "%Var1%"=="" (
echo "Queue is empty."
exit /b
) ELSE (
echo "Queue is full."
exit /b
)

How can I test to see if the txt file is empty? I've also found a string (on this forum) that can detect a file's size but it doesn't make any sense. How do users employ these characters? %%~zA How can I get it to load the filesize into a variable so that I can echo it into the command prompt?

Thanks


See More: BAT File conditional check for empty string

Report •


#1
April 29, 2009 at 12:33:14
I think I found a solution at the command prompt:

for %I in (queue.txt) do @echo %~zI

How can use this to load up the filesize integer into a variable?


Report •

#2
April 29, 2009 at 12:51:31
I got a temporary thing to work for now. If there is an easier way to do this, please post to the thread. This is pretty round-a-bout for just a filesize check.

for %%I in (queue.txt) Do (
echo %%~zI
IF %%~zI==0 (
echo "File Empty..."
)
)


Report •

Related Solutions


Ask Question