I use this to find if a file exist on a users system at the time of running setup.exe. If the file exist I can then take other action. This example only searches for the file once, if found, returns the path.
PARAMETERS lcPath, lcfile ** find file located in the path passed or subfolder IF PARAMETERS() < 1 RETURN -1 ENDIF IF EMPTY(lcPath) lcPath = "C:\" ENDIF IF EMPTY(lcfile) RETURN -1 ENDIF LOCAL hFind, lcFindBuffer, lnAttr, lcFilename, lcFindFileBuffer, hFindFile
** buffer used to search for the file in each folder identified lcFindFileBuffer = REPLI(CHR(0), FIND_DATA_SIZE) ** buffer used to start search of path passed lcFindBuffer = REPLI(CHR(0), FIND_DATA_SIZE)
DO WHILE .T. lnAttr = buf2dword(SUBSTR(lcFindBuffer, 1,4)) lcFilename = SUBSTR(lcFindBuffer, 45,MAX_PATH) lcFilename = LEFT(lcFilename, AT(CHR(0),lcFilename)-1)
** test for directory IF BITAND(lnAttr, FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY * for a directory IF NOT "." $ lcFilename ** look for file in ths folder hFindFile = FindFirstFile (lcPath + lcFilename + "\" + lcfile, @lcFindFileBuffer) IF hFindFile != INVALID_HANDLE_VALUE && file located quit with the path to the file FindClose(hFind) FindClose(hFindFile) RETURN lcPath + lcFilename + "\" ENDIF ENDIF ENDIF IF FindNextFile (hFind, @lcFindBuffer) = 0 EXIT ENDIF ENDDO FindClose(hFind) RETURN .f.