改了一下,处理异常情况。
DECLARE LONG FindFirstFile IN Kernel32 STRING@, STRING@
DECLARE LONG FindNextFile IN Kernel32 LONG, STRING@
DECLARE LONG FindClose IN Kernel32 LONG
DECLARE LONG GetLastError IN Kernel32
cPath = "D:\" &&GETDIR()
IF EMPTY(cPath)
RETURN
ENDIF
DIMENSION arrDIR[1], arrFile[1], arrError[1]
arrDIR[1] = cPath
stFD = SPACE(320)
nCountD = 1
nCountF = 0
nCountE = 0
FOR EACH cPath IN arrDIR
hf = FindFirstFile(cPath+"*.*", @stFD)
IF hf == -1
nCountE = nCountE + 1
DIMENSION arrError[nCountE]
arrError[nCountE] = "Error:"+TRANSFORM(GetLastError())+ "
"+cPath
LOOP
ENDIF
DO WHILE .T.
nFileAttr = CTOBIN(SUBSTR(stFD,1,4),"4RS")
cFileName = SUBSTR(stFD,45,260)
cFileName = LEFT(cFileName, AT(0h00,cFileName)-1)
IF BITAND(nFileAttr,0x10) != 0
&&目录
IF !(cFileName==".") AND !(cFileName=="..")
nCountD = nCountD + 1
DIMENSION arrDIR[nCountD]
arrDIR[nCountD] = cPath + cFileName + "\"
ENDIF
ELSE
&&文件
nCountF = nCountF + 1
DIMENSION arrFile[nCountF]
arrFile[nCountF] = cPath + cFileName
ENDIF
IF FindNextFile(hf, @stFD) == 0
EXIT
ENDIF
ENDDO
FindClose(hf)
ENDFOR
? nCountF,"个文件", nCountD,"个文件夹", nCountE,"个文件夹搜索出现异常"
CREATE CURSOR tt (fn C(240))
DIMENSION arrFile[nCountF,1]
APPEND FROM ARRAY arrFile
GO TOP
BROWSE
ZAP
DIMENSION arrError[nCountE,1]
APPEND FROM ARRAY arrError
GO TOP
BROWSE