以下是引用瓜瓜1990在2020-6-13 17:45:26的发言:
递归调用adir()
SET SAFETY OFF
CREATE TABLE temp (文件名 m,文件类型 c(6),完整路径 m)
DECLARE aReturnDirectory(1) &&建立返回目录数组
nCount=FindDirectory(@aReturnDirectory,"D:\")
BROWSE
FUNCTION FindDirectory
lPARAMETERS taDireArray,tcPath,lnReCurLevel &&接收数组名、路径名、递归层数(函数内部用)参数
LOCAL laSub[1],i,lnSubDirCount,lnLen
IF PARAMETERS()<3 &&第一次调用该程序时不会传递 lnReCurLevel 参数
lnReCurLevel=0
ENDIF
IF RIGHT(tcPath,1)# "\"
tcPath=tcPath+"\"
ENDIF
IF lnReCurLevel=0
DECLARE taFileArray[1] &&存放文件数组
DECLARE taDireArray[1] &&存放目录数组
If DIRECTORY(tcPath) &&只需在第 0 层检查目录是否存在
taDireArray[1]=tcPath
ELSE
RETURN 0
ENDIF
ELSE
DECLARE taDireArray[ALEN(taDireArray)+1]
taDireArray[ALEN(taDireArray)]=tcPath
ENDIF
lnSubDirCount=ADIR(laSub,tcPath+"*.*","DHS")
FOR i=1 TO lnSubDirCount
IF "D" $ laSub[i,5] AND ! laSub[i,1]=="." AND ! laSub[i,1]==".."
*!* 递归调用 FindDirectory()函数
FindDirectory(@taDireArray,tcPath+laSub[i,1],lnReCurLevel+1)
ELSE
IF ! laSub[i,1]=="." AND ! laSub[i,1]==".."
DECLARE taFileArray[ALEN(taFileArray)+1]
taFileArray[ALEN(taFileArray)]=tcPath+laSub[i,1]
INSERT INTO temp (文件名,文件类型,完整路径) VALUES (juststem(tcPath+laSub[i,1]),justext(tcPath+laSub[i,1]),justpath(tcPath+laSub[i,1]))
ENDIF
ENDIF
ENDFOR
RETURN ALEN(taFileArray)
递归调用adir()
SET SAFETY OFF
CREATE TABLE temp (文件名 m,文件类型 c(6),完整路径 m)
DECLARE aReturnDirectory(1) &&建立返回目录数组
nCount=FindDirectory(@aReturnDirectory,"D:\")
BROWSE
FUNCTION FindDirectory
lPARAMETERS taDireArray,tcPath,lnReCurLevel &&接收数组名、路径名、递归层数(函数内部用)参数
LOCAL laSub[1],i,lnSubDirCount,lnLen
IF PARAMETERS()<3 &&第一次调用该程序时不会传递 lnReCurLevel 参数
lnReCurLevel=0
ENDIF
IF RIGHT(tcPath,1)# "\"
tcPath=tcPath+"\"
ENDIF
IF lnReCurLevel=0
DECLARE taFileArray[1] &&存放文件数组
DECLARE taDireArray[1] &&存放目录数组
If DIRECTORY(tcPath) &&只需在第 0 层检查目录是否存在
taDireArray[1]=tcPath
ELSE
RETURN 0
ENDIF
ELSE
DECLARE taDireArray[ALEN(taDireArray)+1]
taDireArray[ALEN(taDireArray)]=tcPath
ENDIF
lnSubDirCount=ADIR(laSub,tcPath+"*.*","DHS")
FOR i=1 TO lnSubDirCount
IF "D" $ laSub[i,5] AND ! laSub[i,1]=="." AND ! laSub[i,1]==".."
*!* 递归调用 FindDirectory()函数
FindDirectory(@taDireArray,tcPath+laSub[i,1],lnReCurLevel+1)
ELSE
IF ! laSub[i,1]=="." AND ! laSub[i,1]==".."
DECLARE taFileArray[ALEN(taFileArray)+1]
taFileArray[ALEN(taFileArray)]=tcPath+laSub[i,1]
INSERT INTO temp (文件名,文件类型,完整路径) VALUES (juststem(tcPath+laSub[i,1]),justext(tcPath+laSub[i,1]),justpath(tcPath+laSub[i,1]))
ENDIF
ENDIF
ENDFOR
RETURN ALEN(taFileArray)