aqif
Registered User.
- Local time
- Today, 06:54
- Joined
- Jul 9, 2001
- Messages
- 158
Hi
I am trying to develope a utility which will scan all the subfolders within a folder and will return the total file count and file sizes in a tabular form. The code so far is only working up to first level of subfolders. What can I do in the code to make it work for all the indefinite levels of subfolders. I am sure it requires a little tweaking but not sure how.
Here's my Code
---------------
Dim objFSO As FileSystemObject
Dim objFolder As Folder
Dim objFiles As File
Dim strCount As Long
Dim strFileNames As String
Dim strSize As Long
Dim strTotalCount, strTotalSize As Long
Me.TxtStatistics = Null
Me.TxtFileAtt = Null
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("D:\Aqif")
'To scan root files
'------------------
For Each objFiles In objFolder.Files
strSize = strSize + Round(objFiles.Size / 1024, 2)
strCount = strCount + 1
Next
Me.TxtStatistics = Me.TxtStatistics & vbCrLf & " " & objFolder.Path '& vbCrLf & "Total files: " & strCount & " " & "Total size (in KB): " & strSize & " (in MB): " & Round(strSize / 1024, 2) & vbCrLf
Me.TxtFileAtt = Me.TxtFileAtt & vbCrLf & " " & Right(" " & Format(strCount, "0"), 4) & " " & Right(" " & Format(strSize, "0.00"), 9) & " " & Right(" " & Format(strSize / 1024, "0.00"), 7)
strTotalCount = strCount
strTotalSize = strSize
strSize = 0
strCount = 0
'To scan sub folders
'-------------------
For Each objFolder In objFolder.SubFolders
For Each objFiles In objFolder.Files
strSize = strSize + Round(objFiles.Size / 1024, 2)
strCount = strCount + 1
Next
Me.TxtStatistics = Me.TxtStatistics & vbCrLf & " " & objFolder.Path '& vbCrLf & "Total files: " & strCount & " " & "Total size (in KB): " & strSize & " (in MB): " & Round(strSize / 1024, 2) & vbCrLf
Me.TxtFileAtt = Me.TxtFileAtt & vbCrLf & " " & Right(" " & Format(strCount, "0"), 4) & " " & Right(" " & Format(strSize, "0.00"), 9) & " " & Right(" " & Format(strSize / 1024, "0.00"), 7)
strTotalCount = strTotalCount + strCount
strTotalSize = strTotalSize + strSize
strSize = 0
strCount = 0
Next
Msgbox (strTotalCount & "---" & strTotalSize)
Any suggestions?
Cheers!
Aqif
I am trying to develope a utility which will scan all the subfolders within a folder and will return the total file count and file sizes in a tabular form. The code so far is only working up to first level of subfolders. What can I do in the code to make it work for all the indefinite levels of subfolders. I am sure it requires a little tweaking but not sure how.
Here's my Code
---------------
Dim objFSO As FileSystemObject
Dim objFolder As Folder
Dim objFiles As File
Dim strCount As Long
Dim strFileNames As String
Dim strSize As Long
Dim strTotalCount, strTotalSize As Long
Me.TxtStatistics = Null
Me.TxtFileAtt = Null
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("D:\Aqif")
'To scan root files
'------------------
For Each objFiles In objFolder.Files
strSize = strSize + Round(objFiles.Size / 1024, 2)
strCount = strCount + 1
Next
Me.TxtStatistics = Me.TxtStatistics & vbCrLf & " " & objFolder.Path '& vbCrLf & "Total files: " & strCount & " " & "Total size (in KB): " & strSize & " (in MB): " & Round(strSize / 1024, 2) & vbCrLf
Me.TxtFileAtt = Me.TxtFileAtt & vbCrLf & " " & Right(" " & Format(strCount, "0"), 4) & " " & Right(" " & Format(strSize, "0.00"), 9) & " " & Right(" " & Format(strSize / 1024, "0.00"), 7)
strTotalCount = strCount
strTotalSize = strSize
strSize = 0
strCount = 0
'To scan sub folders
'-------------------
For Each objFolder In objFolder.SubFolders
For Each objFiles In objFolder.Files
strSize = strSize + Round(objFiles.Size / 1024, 2)
strCount = strCount + 1
Next
Me.TxtStatistics = Me.TxtStatistics & vbCrLf & " " & objFolder.Path '& vbCrLf & "Total files: " & strCount & " " & "Total size (in KB): " & strSize & " (in MB): " & Round(strSize / 1024, 2) & vbCrLf
Me.TxtFileAtt = Me.TxtFileAtt & vbCrLf & " " & Right(" " & Format(strCount, "0"), 4) & " " & Right(" " & Format(strSize, "0.00"), 9) & " " & Right(" " & Format(strSize / 1024, "0.00"), 7)
strTotalCount = strTotalCount + strCount
strTotalSize = strTotalSize + strSize
strSize = 0
strCount = 0
Next
Msgbox (strTotalCount & "---" & strTotalSize)
Any suggestions?
Cheers!
Aqif