Checking for File Size & using OR Statements

Posted on 2005-05-05
Last Modified: 2008-02-01
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?

Question by:ben1211
    LVL 9

    Expert Comment

    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.
    LVL 13

    Expert Comment

    You'll need a small utility to get the file size - try "grade13" on this page:

    "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.

    LVL 13

    Expert Comment

    Here are some more batch tools:
    and a whole list of links:
    LVL 2

    Expert Comment

    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:
    CALL /?

    good luck
    LVL 23

    Expert Comment

    by:Mohammed Hamada
    LVL 2

    Accepted Solution

    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

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Suggested Solutions

    As the title indicates, I have done this before. It chills me everytime I update the OS on my phone, ( because one time I did this and I essentially had a bricked …
    Windows 7 does not have the best desktop search built in. This is something Windows 7 users have struggled with. You type something in, and your search results don’t always match what you are looking for, or it doesn’t actually work at all. There ar…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now