Listing files in a MS Explorer folder in spreadsheet

drdrfaulkner

New Member
Joined
Oct 15, 2002
Messages
5
I have a folder in Windows Explorer containing numerous files I want to list in a spreadsheet without cutting an pasting them individually. Is there a way I can do this?
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Mark O'Brien

MrExcel MVP
Joined
Feb 15, 2002
Messages
3,530
Here's an example ripped directly from XL-Dennis in the thread:

http://216.92.17.166/board/viewtopic.php?topic=21442&forum=2

I liked Ivan's solution, but couldn't quite get it to work. I especially liked the way he got the directoy path as well, but I couldn't be bothered ripping that out and incorporating it. I've tinkered with XL-Dennis's solution so that you don't have to tinker with any references.<pre>
Sub List_Files()
Dim fsoObj As Object 'Scripting.FileSystemObject
Dim fsoMapp As Object 'Scripting.Folder
Dim fsoFil As Object 'Scripting.File
Dim sFolder As String
Dim i As Long

'Change this to whatever directory you want
sFolder = "C:Temp"

Set fsoObj = CreateObject("Scripting.FileSystemObject")

'Set fsoObj = New Scripting.FileSystemObject
Set fsoMapp = fsoObj.GetFolder(sFolder)

With Range("A1:H1")
.Value = Array("Filename", "Created", "Last changed", "Size", "Type", _
"Drive", "Folder", "Path")
.Font.Bold = True
End With

i = 0
If Not fsoMapp Is Nothing Then
For Each fsoFil In fsoMapp.Files
If fsoFil Like "*.xls" Then
i = i + 1
With fsoFil
Cells(1 + i, 1).Value = .Name
Cells(1 + i, 2).Value = .DateCreated
Cells(1 + i, 3).Value = .DateLastModified
Cells(1 + i, 4).Value = .Size
Cells(1 + i, 5).Value = .Type
Cells(1 + i, 6).Value = .Drive
Cells(1 + i, 7).Value = .ParentFolder
Cells(1 + i, 8).Value = .Path
End With
End If
Next
End If

Columns("A:H").EntireColumn.AutoFit

Set fsoFil = Nothing
Set fsoMapp = Nothing
Set fsoObj = Nothing
End Sub</pre>

HTH

_________________<font color = green> Mark O'Brien
This message was edited by Mark O'Brien on 2002-10-17 09:51
 

drdrfaulkner

New Member
Joined
Oct 15, 2002
Messages
5
I tried the script, but got only column names across the top of the spreadsheet. I'll try again tomorrow.
 

Forum statistics

Threads
1,144,509
Messages
5,724,770
Members
422,577
Latest member
kayth891

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top