• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 784
  • Last Modified:

KiXtart - getdirsize function has limit of 2gb.

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

Here's the kix part
;----------------
$tempfile=c:\size.txt
$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
  else
  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)      
      Do            
            $TotalDirSize = $TotalDirSize + GetFileSize($file)
            $file = ReadLine(1)      
            $GetDirSize = $totaldirsize / "1048576"
      Until @ERROR <> 0       
            $nul=Close(1)
            Del $tempfile      
      EndIf      
 EndFunction
0
craylord
Asked:
craylord
  • 3
  • 2
1 Solution
 
WallsyCommented:
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.

HTH,

Wallsy
0
 
craylordAuthor Commented:
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.
0
 
WallsyCommented:
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.

Cheers,

Wallsy
0
 
craylordAuthor Commented:
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.
0
 
WallsyCommented:
Craylord,

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!
0

Featured Post

Technology Partners: 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!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now