Import a File Listin

  • Thread starter Thread starter Dennis
  • Start date Start date
D

Dennis

Is there a way to pull a list of all the files on your system and also the
size into a work sheet using VBA?


TIA
Dennis
============
 
Man, now that's some VBA!
I'd like to have it do the entire drive tho. With this, if I select C:\, it
only lists the files in the root. Do you how to tweak this?

Dennis
=========
 
Hi Dennis
some code to start with looping through subdirectories (add the file
size, etc.)


Option Explicit
Sub beginhere()
GetDirectories ("D:\")
End Sub

Sub GetDirectories(thisdir As String)
Dim fso As New FileSystemObject, flders
Dim fldr As Folder, fl As File
Dim ws As New Worksheet, rw As Integer
Set fso = New FileSystemObject
Set flders = fso.GetFolder(thisdir)
For Each fldr In flders.SubFolders
GetDirectories CStr(fldr)
Next
rw = 1
Set ws = Worksheets.Add
ws.Cells(rw, 1) = "folder:" & CStr(thisdir)
For Each fl In flders.Files
rw = rw + 1
ws.Cells(rw, 2) = CStr(fl.Name)
Next
End Sub
 
Back
Top