Mr Skunk, recursive treewalk

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Fangbeast.

Mr Skunk, I have been using the below routine you gave me in my cataloguer and it works great for that but, it only returns searches for queries after the period "." so I cannot use it for general searches.

How can it be modified to return matches on either side of the argument?

For now, if I send it ".doc" as the pattern, it will find all documents. If I sent it "doc." or "doc", it will not find anything. Sorry to bother you but I don't quite know how to modify it.

:(

;-----------------------------------------------------------------------------
Procedure GetList(SourceDirectory$, Start, Pattern$)

If ExamineDirectory(Start, SourceDirectory$, "*.*")
Repeat
Type = NextDirectoryEntry()
If Type = 2
If DirectoryEntryName() "." And DirectoryEntryName() ".."
a$ = SourceDirectory$ + DirectoryEntryName() + "\"
GetList(a$, Start + 1, Pattern$)
UseDirectory(Start)
EndIf
Else
If Type = 1 And Right(UCase(DirectoryEntryName()),Len(Pattern$)) = UCase(Pattern$)
temp$ = SourceDirectory$ + DirectoryEntryName()
file$ = GetFilePart(temp$)
path$ = GetPathPart(temp$)
PrintN(file$ + " -- " + path$)
EndIf
EndIf
Until Type = 0
EndIf
EndProcedure

;-----------------------------------------------------------------------------
If OpenConsole()
GetList("C:\",0, "upgrad")
EndIf

String$ = Input()
CloseConsole()

Fangles
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Fangbeast.

Since Mr SKunk didn't see the message, I decided to play around and figured it out. Below is my adaptation for a case insensitive file search that will operate on ANY portion of the string found, not just either a full wildcard or everything after the dot.

;-----------------------------------------------------------------------------
Procedure GetList(SourceDirectory$, Start, Pattern$)

If ExamineDirectory(Start, SourceDirectory$, "*.*")
Repeat
Type = NextDirectoryEntry()
If Type = 2
If DirectoryEntryName() "." And DirectoryEntryName() ".."
a$ = SourceDirectory$ + DirectoryEntryName() + "\"
GetList(a$, Start + 1, Pattern$)
UseDirectory(Start)
EndIf
Else
If Type = 1 And FindString(UCase(DirectoryEntryName()), UCase(Pattern$), 1) 0
TempPos = FindString(UCase(DirectoryEntryName()), UCase(Pattern$), 1)
Temp$ = SourceDirectory$ + Mid(DirectoryEntryName(), TempPos, Len(Pattern$))
PrintN(Temp$)
EndIf
EndIf
Until Type = 0
EndIf
EndProcedure

;-----------------------------------------------------------------------------
If OpenConsole()
GetList("C:\",0, "word") ; this will find "word" anywhere in a string
EndIf

String$ = Input()
CloseConsole()




Fangles
Post Reply