Does anyone have any search directory code... or can someone see errors.. it prints two files and on the second one..it's repeated..
lstDirectories.Clear
' Get the directory path names in Path chosen.
ltPath = lblType1Path(0).Caption & "\" ' Set the path.
MyClient1 = txtPlanId.Text ' "00298"
If Len(MyClient1) < 1 Then
MyClient2 = "*.xls"
Else
MyClient2 = "*" + MyClient1 + "*.xls"
End If
MyClient3 = ltPath + MyClient2
ltTarget = ".xls"
' file exists, the first file found is returned.
lvFname = Dir(MyClient3)
' Retrieve the first entry.
lvName = Dir(ltPath, vbDirectory)
lbFileExists = (Dir(MyClient3) <> ""
ltDirSearch = ltPath + MyClient2
lvFname = Dir(ltPath, vbNormal)
Do While lbFileExists ' Start the loop.
' Ignore the current directory and the encompassing directory.
If lvFname <> "." And lvFname <> ".." Then
' Use bitwise comparison to make sure lvName is a directory.
If (GetAttr(ltPath & lvFname) And vbDirectory) <> vbDirectory Then
iPosition = 1
ltLongstring = lvFname
If InStr(iPosition, ltLongstring, ltTarget) Then
Debug.Print "lvFname" & lvFname ' Display entry only if it
Debug.Print "lvname" & lvName ' Display entry only if it
lstDirectories.AddItem ltPath & lvFname
iCount = iCount + 1
End If ' it doesnt represents a directory.
End If
End If
' Call Dir again without arguments to return the next file in the
' same directory.
lbFileExists = (Dir(MyClient2) <> ""
lvFname = Dir
lvName = Dir ' Get next entry.
Loop
iCountStrings = iCount
lstDirectories.Clear
' Get the directory path names in Path chosen.
ltPath = lblType1Path(0).Caption & "\" ' Set the path.
MyClient1 = txtPlanId.Text ' "00298"
If Len(MyClient1) < 1 Then
MyClient2 = "*.xls"
Else
MyClient2 = "*" + MyClient1 + "*.xls"
End If
MyClient3 = ltPath + MyClient2
ltTarget = ".xls"
' file exists, the first file found is returned.
lvFname = Dir(MyClient3)
' Retrieve the first entry.
lvName = Dir(ltPath, vbDirectory)
lbFileExists = (Dir(MyClient3) <> ""
ltDirSearch = ltPath + MyClient2
lvFname = Dir(ltPath, vbNormal)
Do While lbFileExists ' Start the loop.
' Ignore the current directory and the encompassing directory.
If lvFname <> "." And lvFname <> ".." Then
' Use bitwise comparison to make sure lvName is a directory.
If (GetAttr(ltPath & lvFname) And vbDirectory) <> vbDirectory Then
iPosition = 1
ltLongstring = lvFname
If InStr(iPosition, ltLongstring, ltTarget) Then
Debug.Print "lvFname" & lvFname ' Display entry only if it
Debug.Print "lvname" & lvName ' Display entry only if it
lstDirectories.AddItem ltPath & lvFname
iCount = iCount + 1
End If ' it doesnt represents a directory.
End If
End If
' Call Dir again without arguments to return the next file in the
' same directory.
lbFileExists = (Dir(MyClient2) <> ""
lvFname = Dir
lvName = Dir ' Get next entry.
Loop
iCountStrings = iCount