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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List Folders

Status
Not open for further replies.

Pegullo

Programmer
Apr 14, 2012
5
IT
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
 


Sa are you saying that on the first time thru, you do NOT get the folders in "C:\Documents and Settings\Luca_01\Documenti\"???

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Set flds = fso.GetFolder(dr[!] & "\"[/!]).SubFolders

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I'm sorry for my bad english (i write from italy) but I'm tryng to explain that..... when i run the code the first time I obtain (about Drive C) a result like:

Disco C...100Gb/77Gb
Folder A....2Mb
Folder B....44Mb
Folder D....12Mb

If I re-run the same code, I obtain information about the subfolders of the folder "C:\Documents and Settings\Luca_01\Documenti\".

You can try the code on your own.

Thanks in advance!
 
well....no. I'll try later but i can't understand the mean of: (dr & "\"). Can you explain me please?
 
PHV..I've tryed and now It's OK!!!
But for me is a mistery teh syntax tah you've suggested to me.

Thank You a lot!!!
 
I simply suggested to use the root directory of the drive instead of their current directory.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
..but I checked before to run the macro that no application was pointing to any folder of drive C:\. Why I obtain in the second running the result about the subfolders of C:\Documents and Settings\Luca_01\Documenti\ but not in the first run ??

I can't explain to me....?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top