KiXtart - getdirsize function has limit of 2gb.

Posted on 2005-04-07
Last Modified: 2008-01-09
Heres the situation. We use kix scripts and I've made one that will copy the user's desktop, favorites, my documents and pst/pab files to a network for incremental backup. This will turn into an automatic backup solution for users. The hitch is each user is currently limited to 1Gb of storage on the server. Some of the users assuredly have more than 1Gb between all the folders. I've found a function that will tabulate the size of a directory, but if a folder is more than 2Gb it will only list that much. What I am looking for:
I would like to put a check in place to make sure if a user's combined data is over 1Gb. If it is, it doesn't copy but puts a log on a share, the log part I already know how.
Can the function be modified to to loop the division of its results. Like if after 984,226,256 bytes is counted and divided, put into a different variable to be added together later. Like 1000mb +1000mb + 1000mb +578mb would the display a correct result of 3578mb instead of the limit 19xxmb? Currently I have 500 pts for this but I will gladly give lots more if you can help.
*Note, everything works fine, it's just the size that's the stickler. I could go eventually go by a server with tons of space, but this would be nicer.

Here's the kix part
$mydocuments=ReadValue("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Personal")
$docsize=getdirsize($mydocuments, $tempfile)
at (1,1) $docsize  ; this is just to display the size for testing
If $docsize > "1000"
copy log file and exit.. blah
  copy the stuff
end if

Alternatively I would like to add the totals of the each getdirsize and make sure they are not over 1000 combined.
Here is the function

 Function GetDirSize($path,$tempfile)      
 $dir="dir /s /b /a-d " + '"$path"' + " > " + '"$tempfile"'
 Shell "%comspec% /c" + $dir      
      If Open(1,$tempfile)=0
            $file = ReadLine(1)      
            $TotalDirSize = $TotalDirSize + GetFileSize($file)
            $file = ReadLine(1)      
            $GetDirSize = $totaldirsize / "1048576"
      Until @ERROR <> 0       
            Del $tempfile      
Question by:craylord
    LVL 6

    Accepted Solution

    Hi Craylord,

    I think your issue isn't to do with the GetFileSize limit, but the kix variable limit - your variable $TotalDirSize can't be bigger than 2,147,483,647 (ref Kix2001.DOC, top of page 24).

    The solution is to reduce the GetDirSize in your loop instead of at the end, ie
             $TotalDirSize = $TotalDirSize + GetFileSize($file)
              $file = ReadLine(1)    
              $GetDirSize = $totaldirsize / "1048576"
    should be
             $GetDirSize = $GetDirSize + GetFileSize($file) / "1048576"
              $file = ReadLine(1)    

    That way your variable stays small.


    LVL 16

    Author Comment

    Thanks Wallsy,

    The really weird thing is your line in the script ran fine under another pc, but not mine, I had to add ( ).

    $GetDirSize = $GetDirSize + GetFileSize($file) / "1048576"
    $GetDirSize = ($GetDirSize + GetFileSize($file)) / "1048576"

    But the results weren't what the size was. However, you did demonstrate how to keep the variable small during the loop. Just a bit too small. :) 0mb shoulda been 4500mb and 6800mb was 5mb.

    Your suggestions did make me realize I needed to zero out the $totaldirsize and $getdirsize to correctly add multiple folders.
    LVL 6

    Expert Comment

    The second one wouldn't work because you're dividing the total by 1 million every time you add a file!

    You could try:
    $GetDirSize = $GetDirSize + (GetFileSize($file) / "1048576")

    And yes, you will need to put $GetDirSize = 0 at the start of the function as well.


    LVL 16

    Author Comment

    Yeah, I tried moving the ( ) to the second half, but the totals were always way small. Most likely smaller files were getting added as 0.
    LVL 6

    Expert Comment


    Thanks for the points, but I'm not entirely satisfied with the solution, so here's something else to try!

    You could change your DOS command to:

    $dir="for /f " + CHR(34) + "tokens=1,2,3,4" + CHR(34) + " %%i in ('dir /-c /s " + $path + " ^| find /i " + CHR(34) + "File(s)" + CHR(34) + "') do @echo %%k > " + $tempfile

    This should put the final summary size of all files listed in the temp file without thousand separators, for easier manipulation.

    It may require a little fine-tuning what with all the speechmarks, though. If you were to type it in at a command prompt yourself it should look like this:

    for /f "tokens=1,2,3,4" %i in ('dir /-c /s YourDir ^| find /i "File(s)"') do @echo %k > TempFile

    If that will help when you're working on the formatting!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    This article shows how to convert a multi-page PDF file into multiple image files, with one image file created for each page of the PDF. It does this by utilizing an excellent, free software package called GraphicsMagick. The solution is amazingly s…
    Article by: Rob
    Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
    The viewer will learn how to create multiple layers to apply various filters and how to delete areas from each layer’s filter.
    Viewers will learn how to use the Hootsuite Dashboard.

    779 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

    11 Experts available now in Live!

    Get 1:1 Help Now