Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
FUNCTION SUBFOLDERSEARCH
PARAMETERS m.TOPLEVEL,m.MASK,m.TEMPDIR,m.PROGRESS,m.TEMPFILE,m.TMPDIRS,m.LEAVEOPEN
PRIVATE m.TOPLEVEL,m.MASK,m.TEMPDIR,m.TEMPFILE,m.TMPDIRS,m.LEAVEOPEN,m.PROGRESS,I,X,m.LASTPATH,NUMFILES,NUMDIR
PRIVATE m.OLDAREA
DIMENSION ALIST[1,5],FLIST[1,5]
IF PCOUNT() < 7
** This parameter controls whether the resultant table of file names is left as the current cursor
M.LEAVEOPEN = .F.
ENDIF
IF PCOUNT() < 6
** This one controls the name of the temporary table used to track folders not yet processed
M.TMPDIRS = "TMPDIRS"
ENDIF
IF PCOUNT() < 5
** This one allows the user to specify the name of the table that will hold any filenames located
M.TEMPFILE = "TMPFILES"
ENDIF
IF PCOUNT() < 4
** The fourth parameter controls the use of a wait window to show that something is happening
M.PROGRESS = .F.
ENDIF
IF PCOUNT() < 3
** The third parameter controls the name of the folder to be used for the temporary folder
M.TEMPDIR = "C:\TEMP\"
ENDIF
IF PCOUNT() < 2
** The second parameter is the pattern to be searched for
M.MASK = "*.*"
ENDIF
IF PCOUNT() < 1
** The first parameter is used to specify where the search should start
M.TOPLEVEL = ".\"
ENDIF
M.OLDAREA = SELECT()
** CREATE A COUPLE OF TEMPORARY TABLES - ONE FOR THE FINAL FILENAME LIST (COMPLETE WITH PATHS
SELECT 0
CREATE TABLE (m.TEMPDIR+M.TEMPFILE) FREE (FULLNAME C(240) NOT NULL, FILESIZE N(12,0) NOT NULL, FILEDATE D NOT NULL, FILETIME C(8) NOT NULL, FILEATTR C(20) NOT NULL)
USE (m.TEMPDIR+M.TEMPFILE) ALIAS TMPFILES EXCLUSIVE
INDEX ON FULLNAME TAG TMPFILES
** AND ONE FOR THE FOLDERS TO SEARCH
SELECT 0
CREATE TABLE (m.TEMPDIR+M.TMPDIRS) FREE (FPATH C(240) NOT NULL,PROCESSED C(1) NOT NULL)
USE (m.TEMPDIR+M.TMPDIRS) ALIAS TMPDIRS EXCLUSIVE
** USE AN INDEX TO KEEP CHECKING FOR UNPROCESSED SUBFOLDERS
INDEX ON PROCESSED TAG TMPDIRS
** START BY PUTTING THE 'WHERE TO START' IN LIST OF UNPROCESSED FOLDERS
SELECT TMPDIRS
SET ORDER TO TMPDIRS
APPEND BLANK
REPLACE FPATH WITH m.TOPLEVEL
REPLACE PROCESSED WITH "N"
GO TOP
SELECT TMPDIRS
SET ORDER TO TMPDIRS
SEEK "N"
** SCAN THE LIST OF SUBFOLDERS - LOOKING FOR UNPROCESSED ONES
DO WHILE .NOT. EOF()
** MAKE A NOTE OF THE FOLDERS PATH
M.LASTPATH = ALLTRIM(FPATH)+IIF(RIGHT(ALLTRIM(FPATH),1)<> "\","\","")
WAIT "Checking..." + m.LASTPATH WINDOW NOWAIT TIMEOUT 1
** CHECK FOR FILES MATCHING MASK
NUMFILES = ADIR(FLIST,m.LASTPATH+m.MASK)
FOR I = 1 TO NUMFILES
** IGNORE THE . AND .. ONES
IF FLIST[i,1] <> "." .AND. FLIST[i,1] <> ".."
** STICK THE FILES IN THE FILE LIST
SELECT TMPFILES
APPEND BLANK
*REPLACE FPATH WITH M.LASTPATH
REPLACE FULLNAME WITH m.LASTPATH+FLIST[i,1]
REPLACE FILESIZE WITH FLIST[i,2]
REPLACE FILEDATE WITH FLIST[i,3]
REPLACE FILETIME WITH FLIST[i,4]
REPLACE FILEATTR WITH FLIST[i,5]
ENDIF
NEXT
** MARK THAT FOLDER AS PROCESSED
SELECT TMPDIRS
REPLACE PROCESSED WITH "Y"
** NOW CHECK THE FOLDER FOR SUBFOLDERS - HAVE TO DO THIS BECAUSE THE MASK
** FOR FILES OF INTEREST WILL BE DIFFERENT TO THE ONE FOR FOLDERS
NUMDIR = ADIR(ALIST,m.LASTPATH+"*.*","D")
** FOR EACH FOLDER FOUND
FOR I = 1 TO NUMDIR
** IGNORE THE ONES THAT ARE NOT FOLDERS AND THAT ARE CALLED . OR ..
IF "D"$ALIST[i,5] .AND. ALIST[i,1] <> "." .AND. ALIST[i,1] <> ".."
SELECT TMPDIRS
APPEND BLANK
REPLACE FPATH WITH m.LASTPATH+ALIST[i,1]
REPLACE PROCESSED WITH "N"
ENDIF
NEXT
** LOOK FOR THE NEXT UNPROCESSED FOLDER
WAIT CLEAR
SELECT TMPDIRS
SET ORDER TO TMPDIRS
SEEK "N"
ENDDO
RELEASE FLIST
RELEASE ALIST
SELECT TMPDIRS
USE
SELECT TMPFILES
IF !M.LEAVEOPEN
USE
SELECT(m.OLDAREA)
ENDIF
RETURN(m.TEMPDIR+m.TEMPFILE+IIF(UPPER(RIGHT(M.TEMPFILE,4)) <> ".DBF",".DBF",""))
myTableName = SearchSubFolders("D:\","*.DBC","C:\TEMP\",.T.)
myTableName = SearchSubFolders("D:\","*.DBC","C:\TEMP\",.T.,"TMPFILES","TMPDIRS",.F.)