ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Folder Size/File Count (https://www.excelbanter.com/excel-programming/368992-folder-size-file-count.html)

DMc2004

Folder Size/File Count
 
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

Jake Marx[_3_]

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




NickHK

Folder Size/File Count
 
If you want a fast API method:
http://groups.google.co.uk/group/mic...a70685aa576333

NickHK

"DMc2004" wrote in message
...
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





All times are GMT +1. The time now is 03:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com