Import a File Listin

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
============
 
D

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
=========
 
F

Frank Kabel

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top