FOR Command Differences on NT vs 2000

K

kvp

I'm trying to determine if a text file is empty by using
the following FOR command to set the environment variable
size_ to the number of bytes in a file:

FOR %f in (dummy.txt) do set size_=%~zf

This works correctly on a Win2000 server, but not on a
WinNT server. On a WinNT server, the environment variable
size_ ends up being equal to "%~zf".

Is there a way to make this work on a WinNT box or is
there another method that can be used to determine if a
text file is empty? I read through the 1CMCFAQ.txt found
in tscmd.zip and searched the newsgroup, but found nothing
that might help. Our WinNT server current with all
required updates and has had service pack 6 installed.

Thanks
 
T

Tom Lavedas

If all you need to know is whether it is zero bytes or
not, you could do something like this (for all MS OS's I
can think of) ...

dir dummy.txt | find " 0 bytes">nul
if not errorlevel 0 echo Not zero bytes.
if errorlevel 1 echo Is zero bytes.

Tom Lavedas
===========
 
T

Tom Lavedas

Sorry, I must have been asleep when I wrote that. The
correct formulation is ...

dir dummy.txt | find " 0 bytes">nul
if not errorlevel 1 echo Is zero bytes.
if errorlevel 1 echo Is NOT zero bytes.

Tom Lavedas
===========
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top