Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 389
Default List Directories and Subdirectories

Is there macro make a list in excel of the directories and subdirectories
under a certain directory: For example:

C:\

and then list all the directories and subdirectories in an excel file.

But not the files.

Thank you,

Steven
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default List Directories and Subdirectories

I pulled this code from my archieves. It does exactly what you want and also
gets the sizes (bytes) of each folder.


Dim RowNumber
Sub GetFolderSize()

strFolder = "C:"
RowNumber = 1

Set fso = CreateObject _
("Scripting.FileSystemObject")
Set folder = _
fso.GetFolder(strFolder)

Sheets(1).Cells(RowNumber, 1) = strFolder + "\"
Sheets(1).Cells(RowNumber, 2) = folder.Size
RowNumber = RowNumber + RowNumber

Call GetSubFolderSize(strFolder + "\")
End Sub

Sub GetSubFolderSize(strFolder)
Set fso = CreateObject _
("Scripting.FileSystemObject")

Set folder = _
fso.GetFolder(strFolder)

If folder.subfolders.Count 0 Then
For Each sf In folder.subfolders
On Error GoTo 100
Call GetSubFolderSize(strFolder + sf.Name + "\")
100 Next sf
End If
'folder size in bytes
On Error GoTo 200
If Not folder.isrootfolder Then
FolderSize = folder.Size
Sheets(1).Cells(RowNumber, 2) = FolderSize
Sheets(1).Cells(RowNumber, 1) = strFolder
RowNumber = RowNumber + 1
End If

200 On Error GoTo 0

End Sub


"Steven" wrote:

Is there macro make a list in excel of the directories and subdirectories
under a certain directory: For example:

C:\

and then list all the directories and subdirectories in an excel file.

But not the files.

Thank you,

Steven

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 389
Default List Directories and Subdirectories

That is incredible. Thank you.

"Joel" wrote:

I pulled this code from my archieves. It does exactly what you want and also
gets the sizes (bytes) of each folder.


Dim RowNumber
Sub GetFolderSize()

strFolder = "C:"
RowNumber = 1

Set fso = CreateObject _
("Scripting.FileSystemObject")
Set folder = _
fso.GetFolder(strFolder)

Sheets(1).Cells(RowNumber, 1) = strFolder + "\"
Sheets(1).Cells(RowNumber, 2) = folder.Size
RowNumber = RowNumber + RowNumber

Call GetSubFolderSize(strFolder + "\")
End Sub

Sub GetSubFolderSize(strFolder)
Set fso = CreateObject _
("Scripting.FileSystemObject")

Set folder = _
fso.GetFolder(strFolder)

If folder.subfolders.Count 0 Then
For Each sf In folder.subfolders
On Error GoTo 100
Call GetSubFolderSize(strFolder + sf.Name + "\")
100 Next sf
End If
'folder size in bytes
On Error GoTo 200
If Not folder.isrootfolder Then
FolderSize = folder.Size
Sheets(1).Cells(RowNumber, 2) = FolderSize
Sheets(1).Cells(RowNumber, 1) = strFolder
RowNumber = RowNumber + 1
End If

200 On Error GoTo 0

End Sub


"Steven" wrote:

Is there macro make a list in excel of the directories and subdirectories
under a certain directory: For example:

C:\

and then list all the directories and subdirectories in an excel file.

But not the files.

Thank you,

Steven

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Search Directories/SubDirectories UserForm Patrick Kirk Excel Programming 2 December 23rd 07 02:25 PM
list of all subdirectories in a given directory in excel Peter STEVENS Excel Worksheet Functions 3 February 11th 06 03:32 PM
Create list from directories SoloGIS Excel Discussion (Misc queries) 1 November 22nd 05 09:01 AM
Creating a list of directories mousetrap Excel Programming 1 July 24th 04 05:22 AM
Getting list of directories mousetrap Excel Programming 2 May 29th 04 01:51 PM


All times are GMT +1. The time now is 04:30 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"