Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a file is not empty in Batch

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?

like image 359
laggingreflex Avatar asked Jun 27 '12 11:06

laggingreflex


People also ask

What does 0 |% 0 Do 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).

How do you check that folder is empty or not in CMD?

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.

What does %1 do in batch?

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.

What is set P in batch file?

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.


2 Answers

for /f %%i in ("file.txt") do set size=%%~zi
if %size% gtr 0 echo Not empty
like image 164
Bali C Avatar answered Sep 18 '22 14:09

Bali C


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

like image 23
risingDarkness Avatar answered Sep 21 '22 14:09

risingDarkness