WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Functions

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

DirSize Function

Keywords: 	 dirsize

Question:

I have a directory of about 3Gb. Properties in Windows explorer reports:
Size 3,375,239,227
Size on Disk 3,802,210,304

DirSize(directory,0,1) is 3,364,075,348 -- should match explorer's size(?)
DirSize(directory,1,1) is 3,790,237,696 -- should match explorer's size on disk(?)
Any thoughts on why DirSize isn't matching? I'm in Windows XP 32bit, SP3 with all current patches (I hope).

If it makes any difference, there are no junctions or links. There are 167,621 files and 11,497 directories.

Answer:

A large total size can cause "representational" errors because DirSize uses a floating point accumulator internally.

Does this code match what you see in the Windows Explorer?

#DefineFunction udfShellDirSize( directory )
   objFSO = CreateObject("Scripting.FileSystemObject")
   objFolder = objFSO.GetFolder( directory )
   If objFolder != 0
      size = objFolder.Size
   Else
     Return -1 ;Error: Folder doesnt exist
   EndIf
   objFolder = 0
   objFSO = 0
   Return size
 #EndFunction

 directory = DirWindows(1)
 ret = udfShellDirSize( directory )
 Pause( directory, ret )


Question:

Is there a call or clever bit of programming that will return the total size of a directory tree?

Answer:

The DirSize function will do this (look in the help file). Otherwise download the "File Searcher" extender and use that to write a dir size calculator. Space taken depends on cluster size and whether the file is on a compressed volume or not. The function is asking the OS what the cluster size is. The results from DiskInfo give too large a cluster size for the Fat32 drive. 32768 for a little 3 GB drive; accurate for Fat16.

Here's some information on the DirSize(1) anomalies:

  1. There is a documented MS bug in that Windows 95 will return the incorrect information for hard drives bigger than 2GB.

  2. See what the code below returns. Compare it to what you expect.
    	Disk="C"
    	spc = DiskInfo(disk, 1)
    	bps = DiskInfo(disk, 2)
    	bpc = spc * bps
    	Message("Cluster size on drive C:", bpc)
    
    You'll notice that the results from DiskInfo give too large a cluster size for the Fat32 drive. 32768 for a little 3 GB drive; accurate for Fat16.
Depending on the exact conversion you want you may have to convert the DirSize return value to MB.
MB1=a / (1000*1000)
MB2=a / (1000*1024)
MB3=a / (1024*1024)

answers=strcat("MB1=",mb1,@crlf,"MB2=",mb2,@crlf,mb3)

Message("Answers",answers)

Article ID:   W13051
Filename:   DirSize Function Anomalies.txt
File Created: 2010:04:28:11:36:58
Last Updated: 2010:04:28:11:36:58