Importing directories

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to import a file directory listing from a folder into an Excel spreadsheet? Specifically to have one column with the file name and a second column with the date last modified, without having to type each entry in individually?
 
Hi Pmac

You can run this on a empty sheet to list all files in the folder C:\Data

Sub test2()
Dim i As Long
With Application.FileSearch
.NewSearch
.LookIn = "c:\Data"
.SearchSubFolders = False
.MatchTextExactly = False
.FileType = msoFileTypeAllFiles
If .Execute(msoSortOrderDescending) > 0 Then
MsgBox "There were " & .FoundFiles.Count & " file(s) found."
For i = 1 To .FoundFiles.Count
Cells(i, 1).Value = .FoundFiles(i)
Cells(i, 2).Value = FileDateTime(.FoundFiles(i))
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)




Pmac said:
Is there a way to import a file directory listing from a folder into an Excel spreadsheet? Specifically to have one column
with the file name and a second column with the date last modified, without having to type each entry in individually?
 
Hi Ron
I wanted to thank you for your help on this. The answer was a little too advanced for me at first, but after showing it to some friends at work, we realized it was a VB instruction in the macro section. It worked quite well. Now we will look to do some text string functions so only the file name and not the entire directory path appears in the cell
But I wanted to let you know, your answer really helped and I just wanted to thank you again

Pma

----- Ron de Bruin wrote: ----

Hi Pma

You can run this on a empty sheet to list all files in the folder C:\Dat

Sub test2(
Dim i As Lon
With Application.FileSearc
.NewSearc
.LookIn = "c:\Data
.SearchSubFolders = Fals
.MatchTextExactly = Fals
.FileType = msoFileTypeAllFile
If .Execute(msoSortOrderDescending) > 0 The
MsgBox "There were " & .FoundFiles.Count & " file(s) found.
For i = 1 To .FoundFiles.Coun
Cells(i, 1).Value = .FoundFiles(i
Cells(i, 2).Value = FileDateTime(.FoundFiles(i)
Next
Els
MsgBox "There were no files found.
End I
End Wit
End Su


--
Regards Ron de Brui
(Win XP Pro SP-1 XL2002 SP-2
www.rondebruin.n



Pmac said:
Is there a way to import a file directory listing from a folder into an Excel spreadsheet? Specifically to have one colum
with the file name and a second column with the date last modified, without having to type each entry in individually
 

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

Back
Top