Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: batch variables greater than 32bit?  (Read 3131 times)

0 Members and 1 Guest are viewing this topic.

Grant123

    Topic Starter


    Rookie
    batch variables greater than 32bit?
    « on: June 04, 2009, 07:28:17 AM »
    Hello, I've come up with another problem... I'm trying to find the total size of all the files in a directory (recursive) that have a certain extension.  I've come up with the code, executed it, everything's perfect.  UNTIL it goes beyond the 32bit limit of the variables.

    here's my code:
    Code: [Select]
    set /p directory=Which Directory?
    echo %directory% > output.txt

    echo step1: directory listing
    dir %directory% /s /-c > temp1.txt

    echo step2: refining directory listing
    :: THIS STEP JUST SAVES ALL LINES THAT HAVE A DATE AND REMOVES ALL THE OTHER CRAP AND THEN REMOVES ALL THE DIRECTORY LISTINGS
    Find /I "/200" temp1.txt > temp2.txt
    Find /I "/199" temp1.txt >> temp2.txt
    Find /I "/198" temp1.txt >> temp2.txt
    Del temp1.txt
    Find /I /v "<DIR>" temp2.txt > temp3.txt
    Del temp2.txt

    echo step3: search files
    echo starting .doc
    Find /I ".doc" temp3.txt > temp_doc.txt
    set doc_size = 0
    set %%A = 0
    For /F "tokens=4" %%A in (temp_doc.txt) do (set /a doc_size+=%%A)
    echo .doc size =             %doc_size% bytes >> output.txt
    del temp_doc.txt

    I'm doing this for a bunch of different file types and the problem isn't necessarily with the .doc files but the email collections (.pst) and other groups of files that are bigger than 2 gig.

    So my problem comes when i have a file that is for example: 29332915648 bytes.  this number returns as a negative number which messes everything up.  The problem also comes up when adding up all the sizes, the variable goes beyond 2 gigs (2147483647 bytes since 4294967295 is the 32bit range and anything over 2147483647 comes up negative.)


    You guys have been so helpful and I'm hoping you might be able to give me a hand, otherwise I may have to move on to vbscript or powershell for this :(
    « Last Edit: June 04, 2009, 09:32:57 AM by Grant123 »

    Grant123

      Topic Starter


      Rookie
      Re: batch variables greater than 32bit?
      « Reply #1 on: June 05, 2009, 06:55:34 AM »
      no dice?

      billrich

      • Guest
      Re: batch variables greater than 32bit?
      « Reply #2 on: June 05, 2009, 07:11:21 AM »
      no dice?

      Find /I ".doc" temp3.txt > temp_doc.txt
      Find /I ".doc" temp3.txt >> temp_doc.txt
      ( Will need append (>> ) if more than one line with .doc )


      I believe you are all wet.
      « Last Edit: June 05, 2009, 06:13:59 PM by billrich »

      gh0std0g74



        Apprentice

        Thanked: 37
        Re: batch variables greater than 32bit?
        « Reply #3 on: June 05, 2009, 07:20:25 AM »
        may have to move on to vbscript or powershell for this :(
        then why don't you move on. ?

        devcom



          Apprentice

          Thanked: 37
          Re: batch variables greater than 32bit?
          « Reply #4 on: June 05, 2009, 07:23:45 AM »
          @Grant

          1) how do you want to set %%A without for loop??
          set %%A = 0
          ?

          2) try to use Dias script
          Quote
          Wscript.echo eval(WScript.Arguments(0))

          Save this script as Evaluate.vbs

          Now, (cumbersome) either call it by

          cscript //nologo "Path to\evaluate.vbs" "valid VBS expression" [quotes not always needed but advised]

          http://www.computerhope.com/forum/index.php/topic,77361.0.html

          3) your code can be much smaller ;)
          Download: Choice.exe

          Grant123

            Topic Starter


            Rookie
            Re: batch variables greater than 32bit?
            « Reply #5 on: June 05, 2009, 07:28:33 AM »
            then why don't you move on. ?

            just wanted to see if anyone had any input before I started to teach myself a new language just because of a variable range issue.


            @Grant

            1) how do you want to set %%A without for loop??
            set %%A = 0
            ?

            2) try to use Dias script
            http://www.computerhope.com/forum/index.php/topic,77361.0.html

            3) your code can be much smaller ;)
            1. I did that because since I'm doing it for multiple file extensions and I was afraid that there might be an issue if I reuse %%A.  I imagine that could go away but it never cause a problem so it's stayed.

            2. Looking into that now.  I haven't touched vbscript for about 6 years so I'll have to work on it a bit.

            3.  :-[ i know... Still getting into this scripting stuff and this is a very elementary way of writing it but I'm not familiar with all the shortcuts.