[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 265
  • Last Modified:

Checking for File Size & using OR Statements

I need a Batch File that can check the file size. For example: If <file> or <*.pdf> EQU to a certain file size then do a certain command.

Also, in a MS DOS Batch is it possible to do a OR & AND statment. For example: If %dd% EQU AM OR PM (Echo Yes) Else (Echo No).
I can't use the OR statement. How can it be used? Is it possible?

1 Solution
I'm not sure about DOS.  I would use a VBScript to do that.  Here's a site that has many examples of DOS batch scripts.

You'll need a small utility to get the file size - try "grade13" on this page: http://garbo.uwasa.fi/pc/batchutil.html

"or / and" are not possible in IF's, you'll need to construct something like this for your query

if %dd% EQU AM goto yes
if %dd% EQU PM goto yes
goto no
echo Yes
goto rest
echo No
... continue here

Batch is really a bit outdated, but fun. You'll need lots of small utilities like on that page above. Better would really be a vbscript.

Here are some more batch tools:
and a whole list of links:
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

you dont need any tools...
this is for emulate the OR command.....

if <firstCOND> GOTO ok
if <secondCOND> GOTO ok
GOTO exit


and... for the file size
i think you can use the CALL command...
this is for colling another batch inside a batch

CALL batch2.bat %param1% %param2%

let me give an example:

-->this is batch1.bat
SET f1="file1.pdf"
SET f2="file2.pdf"
CALL batch2.bat %f1% %f2%

-->this is batch2.bat
ECHO %~z1
ECHO %~z2

this ---> %1 <--- is the first argoment (file1.pdf)
this ---> %~z1 <---- is the dimension of the first argoment (file1.pdf)

if your batch2.bat has the "OR statement" and your command you solved it...
for a full list of the parameters use this command in a dos windows:

good luck
Mohammed HamadaSenior IT ConsultantCommented:
i forgot...

if you need more the 9 parameters...
you need command SHIFT

when you tipe SHIFT the 1° argoment become the 2°
i mean:
CALL batch.bat %par1% %par2% %par3%
-- now the %1 is %par1%, %2 is %par2% ect...
-- now the %1 is the %par2%, %2 is %par3%

so if you have more then 9 parameters you can shift for use the 10° the 11° ect...

if you want to do something at *.pdf you need FOR command
this is the use

FOR %%A IN (*.pdf) DO ...

mix all

you need at least 3 file batch

@ECHO off
SET file="yourfile"
CALL batch2.bat %file%
SET file=    <---- this delete the enviroment variable
ECHO finisched....

IF %~z1 EQU <numbar> GOTO ok2
SET flag=0
FOR %%A IN (*.pdf) DO CALL batch3.bat %%A %flag%
IF %flag% EQU 1 GOTO ok1
SET flag=
GOTO out
SET flag=
ECHO work in progress wait...
<your command>
GOTO finish
ECHO noting done!

IF %~z1 EQU <numbar> SET flag=1

(you can put <numbar> in an enviroment variable like flag when calling)
hope this is all you need....

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now