List Files in a Directory

P

plantechbl

I have gotten this code from a previous post (Thank You "KAAK", this
runs very fast) and modified it to work for my specific purpose. The
only thing I can't seem to get it to do is start its file listing in
the second row ("B2"). Thanks in advance

Sub ListFiles02()
'Using FileSearch to list the files in a directory
Dim i As Integer
i = 1
With Application.FileSearch
..NewSearch
..LookIn = "G:\06_Drawings\Drafting System\Standards\Blocks\Casework"
..Filename = "*.dwg"
.SearchSubFolders = True
'.SearchFolders = False
..Execute
For i = 1 To .FoundFiles.Count
Range("B" & i).Value = .FoundFiles(i)
Range("C" & i).Value = FileDateTime(.FoundFiles(i))
'Range("D" & i).Value = FileLen(.FoundFiles(i))
Next


End With


End Sub
 
B

Bob Phillips

Sub ListFiles02()
'Using FileSearch to list the files in a directory
Dim i As Integer
i = 1
With Application.FileSearch
..NewSearch
..LookIn = "G:\06_Drawings\Drafting System\Standards\Blocks\Casework"
..Filename = "*.dwg"
.SearchSubFolders = True
'.SearchFolders = False
..Execute
For i = 1 To .FoundFiles.Count
Range("B" & i + 1).Value = .FoundFiles(i)
Range("C" & i + 1).Value = FileDateTime(.FoundFiles(i))
'Range("D" & i + 1).Value = FileLen(.FoundFiles(i))
Next


End With


End Sub


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 
D

Darren Hill

You need to add 1 to i, like so:

For i = 1 To .FoundFiles.Count
Range("B" & i+1).Value = .FoundFiles(i)
Range("C" & i+1).Value = FileDateTime(.FoundFiles(i))
'Range("D" & i+1).Value = FileLen(.FoundFiles(i))
Next
 
P

plantechbl

That did it! This is the fastest file listing code that I have used
(16,331 files in less than a minute). Thanks again for the replies.
 

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