I'm trying to print in a word file the list of all drives in my PC with total and free space, and for every Drive, print a list of folders in it, with the dimension of every folder.
The first time I run Macro i've no problem. But when I re-run the macro, I obtain for the Disk C the list of the folders contained in the folder "C:\Documents and Settings\Luca_01\Documenti\".
I can't understand WHY!!!
------The Code-------
Sub Chk_Disk_02()
Dim fso As New FileSystemObject
Dim drv As Drives
Dim strText As String
Dim flds As Folders
Set drv = fso.Drives
For Each dr In drv
If dr.IsReady Then
strText = "Disco " & dr.DriveLetter & " " & vbTab & FormatNumber(dr.TotalSize / (1024 ^ 3), 0) & " Gb" _
& " / " & FormatNumber(dr.FreeSpace / (1024 ^ 3), 0) & " Gb"
Selection.TypeText strText
Selection.TypeParagraph
End If
If dr.IsReady Then
Set flds = fso.GetFolder(dr).SubFolders
For Each F In flds
If F.Attributes <> 22 Then
strText = F.Path & vbTab & FormatNumber(F.Size / (1024 ^ 2), 0) & " Mb"
Selection.TypeText strText
Selection.TypeParagraph
End If
Next
End If
Next
End Sub
The first time I run Macro i've no problem. But when I re-run the macro, I obtain for the Disk C the list of the folders contained in the folder "C:\Documents and Settings\Luca_01\Documenti\".
I can't understand WHY!!!
------The Code-------
Sub Chk_Disk_02()
Dim fso As New FileSystemObject
Dim drv As Drives
Dim strText As String
Dim flds As Folders
Set drv = fso.Drives
For Each dr In drv
If dr.IsReady Then
strText = "Disco " & dr.DriveLetter & " " & vbTab & FormatNumber(dr.TotalSize / (1024 ^ 3), 0) & " Gb" _
& " / " & FormatNumber(dr.FreeSpace / (1024 ^ 3), 0) & " Gb"
Selection.TypeText strText
Selection.TypeParagraph
End If
If dr.IsReady Then
Set flds = fso.GetFolder(dr).SubFolders
For Each F In flds
If F.Attributes <> 22 Then
strText = F.Path & vbTab & FormatNumber(F.Size / (1024 ^ 2), 0) & " Mb"
Selection.TypeText strText
Selection.TypeParagraph
End If
Next
End If
Next
End Sub