* Crawl through the directory tree * Init CLOSE DATABASES SET SAFETY OFF M.thispath=JUSTPATH(SYS(16)) SET DEFAULT TO &thispath * Request the starting directory lcRootDir = GETDIR() =Crawl(lcRootDir, 'doc', 'doclist') BROWSE NORM ***************************************************************** * * * * * Crawl down a directory tree and list the name and * * directory of every file of one type in a cursor * * * * USAGE : Crawl(cRootDirectory,cDocumentType,cCursorname) * * * * * * Alan Shepard 30/11/2003 * * * * Checked on VFP7, VFP6 * * * ***************************************************************** FUNCTION Crawl PARAMETERS CurrDir, DocType, CursorName * Create cursor for the results if this is the first time the function * has been called IF TYPE('llFirstTime') = 'U' llFirstTime = .F. CREATE CURSOR &CursorName (filename C(20), dirname C(40)) SELECT (CursorName) ENDIF * Create variables and make them private to this instance of the function LOCAL lnFileCount, lnDirCount, t LOCAL arrFileList(1,1), arrDirList(1,1) STORE 0 TO lnFileCount, lnDirCount, t STORE '' TO arrFileList, arrDirList PRIVATE arrFileList, arrDirList, lnFileCount, lnDirCount, t * Get a list of files in current directory SET DEFAULT TO (CurrDir) lnFileCount = ADIR(arrFileList, '*.'+DocType) * Add file details to cursor FOR t = 1 TO lnFileCount APPEND BLANK REPLACE filename WITH arrFileList[t,1],; dirname WITH CurrDir ENDFOR * Get a list of subdirectories in current directory into array arrDirList lnDirCount = ADIR(arrDirList, '', 'D') * Deal with each subdirectory in turn FOR t = 1 TO lnDirCount IF arrDirList[t,1] <> '.' =Crawl(CurrDir+arrDirList[t,1]+'\', DocType, CursorName) ENDIF ENDFOR ENDFUNC