I feed this routine a full filename and then use StringField to 'peel off' just the first bit I am looking to match and then returning the "Debug "Found close partial match:: " + FileName.s" debug to let me know it found the filename with the partial match.
But, this procedure ends straight away. I used Windows explorer with the same partial string and it can find it so it stands to reason that I don't know what I am doing again:):)
Okay, what did dingo brain forget this time?
Code: Select all
Procedure FindDocument(MissingDocument.s)
SearchTerm.s = Trim(StringField(MissingDocument.s, 1, "-"))
Debug "Missing document name:: " + MissingDocument.s
Debug "Search term to look for:: " + SearchTerm.s
If MissingDocument.s <> #Empty$
SearchDirectory.s = PathRequester("Gimme a path bitch", "")
If SearchDirectory.s <> #Empty$
Debug "Search directory requester:: " + SearchDirectory.s
NewList FoundDirectories.s()
If Right(SearchDirectory.s, 1) = "\"
SearchDirectory.s = Left(SearchDirectory.s, Len(SearchDirectory.s) - 1)
EndIf
AddElement(FoundDirectories.s())
FoundDirectories.s() = SearchDirectory.s
IndexLevel.i = #False
Repeat
SelectElement(FoundDirectories.s(), IndexLevel.i)
DirectoryHandle.i = ExamineDirectory(#PB_Any, FoundDirectories.s(), "*.pdf")
Debug "Directory handle was retrieved:: " + Str(DirectoryHandle.i)
If DirectoryHandle.i <> #False
Path.s = FoundDirectories.s() + "\"
While NextDirectoryEntry(DirectoryHandle.i)
Filename.s = DirectoryEntryName(DirectoryHandle.i)
Select DirectoryEntryType(DirectoryHandle.i)
Case #PB_DirectoryEntry_File
If FindString(FileName.s, SearchTerm.s, 1, #PB_String_NoCase)
Debug "Found close partial match:: " + FileName.s
EndIf
Case #PB_DirectoryEntry_Directory
Filename.s = DirectoryEntryName(DirectoryHandle.i)
If Filename.s <> ".." And Filename.s <> "."
AddElement(FoundDirectories())
FoundDirectories() = Path.s + Filename.s
EndIf
EndSelect
Wend
Else
Debug "Could not get a directory handle, cannot examine anything"
EndIf
IndexLevel.i + 1
Until IndexLevel.i > ListSize(FoundDirectories()) -1
Else
Debug "The search directory was empty"
EndIf
ClearList(FoundDirectories.s())
Else
Debug "Document string was empty"
EndIf
EndProcedure
FindDocument("Tandy Electronics - 3 Sets Of Av Cables - Receipt.Pdf")
End