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

x
  • 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?

0
ben1211
Asked:
ben1211
1 Solution
 
kfullartonCommented:
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.

http://www.robvanderwoude.com/
0
 
softplusCommented:
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
:yes
echo Yes
goto rest
:no
echo No
:rest
... 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.

John
0
 
softplusCommented:
Here are some more batch tools:
http://cyberside.dyn.ee/FreeSoft/batch01.htm
and a whole list of links:
http://www.uwasa.fi/~ts/http/http2.html#batch
0
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!

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

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

:ok
<commands>

: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)

now...
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:
HELP CALL
or
CALL /?

good luck
0
 
Mohammed HamadaSenior IT ConsultantCommented:
0
 
mastrominchioneCommented:
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...
SHIFT
-- 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

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

---batch2.bat----
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
:ok1
SET flag=
:ok2
ECHO work in progress wait...
<your command>
GOTO finish
:out
ECHO noting done!
:finish
-----------------

---batch3.bat----
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....
0

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