Results 1 to 9 of 9
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Win95/DOS batch file size

    Before I write my own (sigh!) Does anyone have any batch file code to determine the size of a file in bytes?

    I'm looking for a method to determine if a file's size is greater than a value specified as a parameter. For example

    ...
    call SetFSize(c:UploadsUnder.zip)
    ...
    echo FSize
    639,456



    I figure I can extract the file size string from a DIR listing, using the method I use to set the date, day of week etc., so it's really a form of string comparison I'm looking for, returning TRUE if a certain figure is exceeded.

  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Win95/DOS batch file size

    Chris: It is not extremely difficult to extract the file size from a DIR listing in batch code. I have a batch file at home which I can send to you tonight if you want it. However, doing a numeric compare using batch code for any condition other than equal is extremely difficult to the point of being impractical. You would be much better off writing a program to do the compare and set an errorlevel. There use to be several programs available in the CompuServe program libraries that would do this.
    Legare Coleman

  4. #3
    Plutonium Lounger Leif's Avatar
    Join Date
    Dec 2000
    Location
    U.K.
    Posts
    14,010
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Win95/DOS batch file size

    <P ID="del"><FONT SIZE=-1>Post deleted by Leif</FONT>

  5. #4
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Win95/DOS batch file size

    In Windows 95?
    Legare Coleman

  6. #5
    Plutonium Lounger Leif's Avatar
    Join Date
    Dec 2000
    Location
    U.K.
    Posts
    14,010
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Win95/DOS batch file size

    Apologies - it does not work. I was running it on a dual boot and just wasn't thinking. I'll edit the above . . .

  7. #6
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Win95/DOS batch file size

    (later) I see you've already realized the error of your ways (grin) but thought to post this anyway. Don't sweat it. It's not a vital issue.


    > for /f "tokens=3" %%a in ('dir FILENAME.ZIP /-c^|findstr ":"') do set size=%%a


    I did and got a syntax error.


    <pre>C:Bat>for /f "tokens=3" %a in ('dir filesize.bat /-c^|findstr ":"') do set size
    =%a
    Syntax error

    C:Bat>echo File size is
    File size is

    C:Bat>
    </pre>


    I tried it first with the original FILENAME.ZIP and thought maybe a problem if the file did not exist, so tried again with FileSize.bat - the name of the batch file. Then I realised i had pasted the code into a batch file, and there's that double-reduction of %%, so I tried the first line from the command line, still no success.

    I can't find a reference to the "/f" switch, or the significance of the "tokens=3". Could you pleaseaborate?

    It's not at all urgent. I thought to explore this as a neater way of obtaining the file size than my current method. I'm still left with the problem of numeric comparison.

  8. #7
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Win95/DOS batch file size

    The reason I wrote my note, and the reason that Lief deleted his original post was that this does not work on Win 95. That syntax did not exist, and is the reason you are getting the syntax error if that is where you are running it. That syntax only exists on Windows NT, and 2000 (and maybe ME which I haven't checked).
    Legare Coleman

  9. #8
    ileacy
    Guest

    Re: Win95/DOS batch file size

    Chris

    If you still need the function I can upload a small Pascal program which accepts two parameters, File Spec and comparison size and returns -1 for parameter error, 0 for equal to, 1 for less than, and 2 for greater than specified size. It will work on any OS.

  10. #9
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Win95/DOS batch file size

    Ooooh! yes please! You can either attach it to a message here or attach it as an email to me.

    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •