There are several ways google throws at me for checking if a file is empty but I need to do the opposite.
If (file is NOT empty)
do things
How would I do this in batch?
What it is: %0|%0 is a fork bomb. It will spawn another process using a pipe | which runs a copy of the same program asynchronously. This hogs the CPU and memory, slowing down the system to a near-halt (or even crash the system).
echo "p=%p%" echo. echo. echo. pause for /F %%i in ('dir /b /a "%p%*"') do ( echo Folder %p% was NOT empty goto :process ) echo Folder %p% was empty :process echo "BLAH, BLAH, BLAH " :end pause exit rem Copy past in notepad to try.
When used in a command line, script, or batch file, %1 is used to represent a variable or matched string. For example, in a Microsoft batch file, %1 can print what is entered after the batch file name.
first: SET /P variable= When batch file reaches this point (when left blank) it will halt and wait for user input. Input then becomes variable.
for /f %%i in ("file.txt") do set size=%%~zi
if %size% gtr 0 echo Not empty
this should work:
for %%R in (test.dat) do if not %%~zR lss 1 echo not empty
help if
says that you can add the NOT
directly after the if
to invert the compare statement
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With