View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jake Marx[_3_] Jake Marx[_3_] is offline
external usenet poster
 
Posts: 860
Default Folder Size/File Count

Hi DMc2004,

You can use the FileSystemObject (part of the Microsoft Scripting Runtime
library) to do this type of thing:

Public Function glGetFolderSizeInMB(rsPath As String) As Long
Dim objFSO As Object

Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FolderExists(rsPath) Then
glGetFolderSizeInMB = objFSO.getfolder(rsPath _
).Size / (1024 ^ 2)
End If

Set objFSO = Nothing
End Function

Public Function glGetFileCount(rsFolderPath As String) As Long
Dim objFSO As Object

Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FolderExists(rsFolderPath) Then
glGetFileCount = objFSO.getfolder(rsFolderPath _
).Files.Count
End If

Set objFSO = Nothing
End Function

Public Function glGetSubfolderCount(rsFolderPath As String) As Long
Dim objFSO As Object

Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FolderExists(rsFolderPath) Then
glGetSubfolderCount = objFSO.getfolder(rsFolderPath _
).Subfolders.Count
End If

Set objFSO = Nothing
End Function


These all use late binding, so there's no need for a reference to the
library. But if you want to play around with the FSO object model a bit,
you could set a reference to Microsoft Scripting Runtime via Tools |
References in the VBE (and Dim the object as Scripting.FileSystemObject) -
that way, you'll get the intelisense.

--
Regards,

Jake Marx
www.longhead.com


[please keep replies in the newsgroup - email address unmonitored]

DMc2004 wrote:
Hi All

I know how to get the size of a Folder and work out the size of Files
within that Folder.

What I would to do is to get the Total Files, Total Folders and Total
Size of a Sub Set of Folders without having to scan through them.

Like with Windows Explorer you can right click on a Folder and bring
up the Properites.

We are analysising the information in Excel.

Many Thanks