* Test Source Code
x=CREATE('FilesList')
*!*	SET TEXTMERGE ON TO TestRecurse NOSHOW
x.FileExtensions = 'sql'
x.Recurse("D:\ROA_RB\DATABASE\SCRIPTURI\")

*!*	SET TEXTMERGE TO
*!*	MODI COMM TestRecurse.txt


DEFINE CLASS FilesList AS Recurse

	*
	PROCEDURE INIT
		DODEFAULT()

		CREATE CURSOR dirlist (DirName C(100), FileName C(250) , FileExt C(3), ;
			rty C(1), FileAttr C(5), FileSize N(12,1), DateMod D, TimeMod C(12))
	ENDPROC && Init
	*
*!*		PROCEDURE ProcessDir(tcDir, tcParentDir)
*!*			DODEFAULT()
*!*		ENDPROC
	PROCEDURE ProcessFile(tcFile, tnSize, tdLastMod, tcTime, tcAttr)
	
		LOCAL loRec
		IF !USED('dirlist')
			RETURN
		ENDIF 
		
		SELECT dirlist
		SCATTER NAME loRec BLANK
		WITH loRec
			.rty='F'
			.DirName = JUSTPATH(tcFile)
			.FileAttr = tcAttr
			.FileName = JUSTFNAME(tcFile)
			.FileExt  = JUSTEXT(tcFile)
			.FileSize = IIF(tnSize > 0, ROUND(tnSize/1024,1) ,0 )
			.DateMod  = tdLastMod
			.TimeMod  = tcTime
		ENDWITH 	
		
        if len(allt(this.FileExtensions)) > 0
            if atc(loRec.FileExt , this.FileExtensions )  = 0
                return
            endif
        endif
		
		INSERT INTO dirlist FROM NAME loRec
	ENDPROC && ProcessFile
	
ENDDEFINE && FilesList

DEFINE CLASS Recurse AS CUSTOM

	FileExtensions = "" && what file extensions it process

	PROCEDURE ProcessFile(tcFile, tnSize, tdLastMod, tcTime, tcAttr)
		* Abstract Method to be overridden in subclasses that actually do something
	ENDPROC

	PROCEDURE ProcessDir(tcDir, tcParentDir)
		* Override this method as desired.
	ENDPROC

	FUNCTION Recurse
		LPARAMETERS pcDir
		LOCAL lnPtr, lnFileCount, laFileList, lcDir, lcFile, lcCurDir
		lcCurDir = FULLPATH(CURDIR())
		CHDIR (pcDir)
		*? 'Dir -> ' + FULLPATH(CURDIR())

		DIMENSION laFileList[1]

		*--- Read the chosen directory.
		lnFileCount = ADIR(laFileList, '*.*', 'D')
		FOR lnPtr = 1 TO lnFileCount

			IF 'D' $ laFileList[lnPtr, 5]
				*--- Get directory name.
				lcDir = laFileList[lnPtr, 1]

				*--- Ignore current and parent directory pointers.
				IF lcDir != '.' AND lcDir != '..'
					*--- Call this routine again.
					THIS.ProcessDir(lcDir, pcDir)
					THIS.Recurse(ADDBS(pcDir)+lcDir)
				ENDIF

			ELSE
				*--- Get the Long file name and process it:
				THIS.ProcessFile( ADDBS(pcDir)+laFileList[lnPtr, 1], laFileList[lnPtr, 2], laFileList[lnPtr, 3], laFileList[lnPtr, 4], laFileList[lnPtr, 5] )
			ENDIF
		ENDFOR

		*--- Move back to parent directory.
		CHDIR (lcCurDir)
		RETURN
	ENDFUNC
ENDDEFINE
