dir

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

Guest

I have specified a directory path and a variable is populated for the first file. When I try to get the next file in the directory by useing a = Dir a is populated with "". This would indicate that all files have been seen but there are 8 more files in the directory that have not been touched. Why would dir give a ""

seeker53
 
Using a = Dir a asks for a second file with the same name. For
subsequent files, use a = Dir.
 
This kind of thing works ok for me:

Option Explicit
Sub testme01()

Application.ScreenUpdating = False

Dim myFiles() As String
Dim fCtr As Long
Dim myFile As String
Dim myPath As String

'change to point at the folder to check
myPath = "c:\my documents\excel\test"
If Right(myPath, 1) <> "\" Then
myPath = myPath & "\"
End If

myFile = Dir(myPath & "*.xls")
If myFile = "" Then
MsgBox "no files found"
Exit Sub
End If

'get the list of files
fCtr = 0
Do While myFile <> ""
fCtr = fCtr + 1
ReDim Preserve myFiles(1 To fCtr)
myFiles(fCtr) = myFile
myFile = Dir()
Loop

If fCtr > 0 Then
For fCtr = LBound(myFiles) To UBound(myFiles)
'do something with mypath & myfiles(fctr)
Next fCtr
End If

Application.ScreenUpdating = True

End Sub
 
Back
Top