Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

search directory errs in vb6

Status
Not open for further replies.

RDC

Programmer
Jan 6, 2001
55
0
0
US
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 = &quot;*.xls&quot;
Else
MyClient2 = &quot;*&quot; + MyClient1 + &quot;*.xls&quot;
End If
MyClient3 = ltPath + MyClient2
ltTarget = &quot;.xls&quot;

' file exists, the first file found is returned.
lvFname = Dir(MyClient3)
' Retrieve the first entry.

lvName = Dir(ltPath, vbDirectory)
lbFileExists = (Dir(MyClient3) <> &quot;&quot;)
ltDirSearch = ltPath + MyClient2
lvFname = Dir(ltPath, vbNormal)

Do While lbFileExists ' Start the loop.
' Ignore the current directory and the encompassing directory.
If lvFname <> &quot;.&quot; And lvFname <> &quot;..&quot; 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 &quot;lvFname&quot; & lvFname ' Display entry only if it
Debug.Print &quot;lvname&quot; & 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) <> &quot;&quot;)
lvFname = Dir
lvName = Dir ' Get next entry.
Loop
iCountStrings = iCount
 
You can use nested/recursive DIR function calls, VB help is not clear but from MSDN

Dir returns the first file name that matches pathname. To get any additional file names that match pathname, call Dir again with no arguments. When no more file names match, Dir returns a zero-length string (&quot; &quot;). Once a zero-length string is returned, you must specify pathname in subsequent calls or an error occurs. You can change to a new pathname without retrieving all of the file names that match the current pathname. However, you can't call the Dir function recursively. Calling Dir with the vbDirectory attribute does not continually return subdirectories.
 
Information is PERFECT... except ONE major setback... please HELP... HOW can I TRAP the FINAL dir call that comes up zero string... the directory list box now fills perfectly UP UNTIl this error and On error statement CANNOT trap it for some reason.. I am desperate.. please help.
 
Sorry missed the follow up question, the way to it depends on the 'surrounding code' heres one idea

Do While lbFileExists
.
.
lvname = dir
if lvname = &quot;&quot; then exit do
loop

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top