*----------------- * FileList.prg * Parameters: * tcSearch: Required. The string to search for * tcStartDir: Optional. The directory to start in. Defaults to current directory * tlText: Optional. If .F. (default) find file names containing tcSearch * If .T. find file contents containing tcSearch * Example: * FileList("vfp", Home()) * to find all files in the Home() directory * containing "vfp" *----------------- LParameters tcSearch, tcStartDir, tlText Local lcSearch, loFolder, loFSO Store "" To lcSearch If Empty(tcSearch) Or Vartype(tcSearch)#"C" MessageBox("Search string is required.", 48, "FileList") Return EndIf lcSearch = Lower(tcSearch) loFSO = CreateObject("Scripting.FileSystemObject") If Empty(tcStartDir) Or Vartype(tcStartDir)#"C" tcStartDir = FullPath(CurDir()) EndIf loFolder = loFSO.GetFolder(tcStartDir) ListX(loFolder, tcSearch, tlText) If Used("cuFindLog") Select cuFindLog Go Top Browse Last Nowait EndIf ************ End of Program ************ *---------- * ListX *---------- Function ListX(toFolder, tcSearch, tlText) Local lcSearch, loFile, loFolder, loSub Store "" To lcSearch Local lcSearch lcSearch = Lower(tcSearch) lcMsg = "Searching " + toFolder.Path Wait Window lcMsg Nowait *-- loop through files in the given folder For Each loFile In toFolder.Files Wait Window lcMsg + Chr(13) + loFile.Name Nowait If tlText If lcSearch $ Lower(FileToStr(loFile.Path)) LogFile(loFile) EndIf Else If lcSearch $ Lower(loFile.Name) LogFile(loFile) EndIf EndIf EndFor *-- loop through subfolders, if any If toFolder.SubFolders.Count > 0 For Each loSub In toFolder.SubFolders ListX(loSub, tcSearch, tlText) EndFor EndIf EndFunc *------------ * LogFile *------------ Function LogFile(toFile) If !Used("cuFindLog") Create Cursor cuFindLog (cfile c(100)) EndIf Insert Into cuFindLog Values (toFile.Path) EndFunc