Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reporting account available space

Status
Not open for further replies.

jpcw

Technical User
Jun 20, 2002
34
GB
Does anyone have a clue on how to leverage the available space available on an IIS6 account into an ASP script? Obviously the FreeSpace() function in the Scripting Host FileSystemObject doesn't work because that is for drives only, and a typical user won't have the appropriate permissions anyway. I'm really stuck on this one and have hunted without success on any number of websites - someone must know the answer because some ISPs provide this in the account administration pages they provide. Thanks in advance.
 
Well, one possibility would be to use the FileSystemObject and sum up the sizes of all the files and all the files in folders (recursively), maybe something like this:
Code:
Dim fso, fol
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set fol = fso.GetFolder("C:\your path here")
Response.Write "The total bytes is: " & SumOfFiles(fol)

'cleanup
Set fol = nothing
Set fso = nothing

'----- recursive file size adder
Function SumOfFiles(folderObject)
   Dim fil, subFol
   Dim total

   'call the total function for each of the subfolders in this directory
   For Each subFol in folderObject.SubFolders
      total = total + SumOfFiles(subFol)
   Next

   'loop through files in this directory and add sizes
   For Each fil in folderObject.Files
      total = total + fil.Size
   Next

   SumOfFiles = total
End Function

You will probably want to do some conversions on that final value that is returned to convert to Mb as the size method returns Bytes, but that should take care ofit. Not sure if it is the fastest way, but shouldn't be slow either.

-T

[sub]01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111[/sub]
The never-completed website:
 
Hi, thanks for the idea, but this just tells me how much space has been *taken*, not how much is left. If you don't know your allocation, or if it could be changed in the future and you want code to adapt automatically, I want to be able to find out how much space is available (i.e. total allocation minus the result from your function or similar).

Thanks again.
 
Ah ha, I've finally dug up something along the lines of what I'm after. I think I need to somehow leverage the "Microsoft.DiskQuota.1" object into a publicly accessible script e.g.

Set colDiskQuotas = CreateObject("Microsoft.DiskQuota.1")

- I've seen code examples using this object, but typically they need admin privaleges to be used. However, if you use the object in read-only mode, one should in theory be able to access it anonymously e.g.

colDiskQuotas.Initialize "d:\\", False
followed by
Set objUserQuota = colDiskQuotas.FindUser("user")
quotUsed = objUserQuota.QuotaUsed
quotLim = objUserQuota.QuotaLimit

However, my attempts thus far have failed, usually at the Initialize command because of not having appropriate permissions to access the disk volume. Has anyone got any cunning ways around this problem?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top