Tamar 是对的……而且它已经存在很长时间了。如果您本地化路径的参数以启动并本地化您正在使用的用于数组处理的变量,那么您应该很好。我个人从不尝试使用 SET DEFAULT TO 或 SET PATH TO。下面的这个方法只是接受一个路径,并以 IT 作为基础来遍历目录树。我什至将结果放在光标中供您根据需要使用。如果您想添加自己的用途,甚至可以添加其他列。唯一没有的是创建日期......只是修改日期。
CREATE CURSOR C_DirWalk ;
( justThePath c(50),;
TheFile c(50),;
TheSize i,;
TheDate d,;
TheTime c(8),;
TheFlags c(5) )
walkTheDir( "C:\SomeFolder\SomeSubFolder\" )
PROCEDURE WalkTheDir
LPARAMETERS justOneDirectory
*/ Make sure it always has the trailing backslash
justOneDirectory = ADDBS( ALLTRIM( justOneDirectory ))
LOCAL ARRAY laOneDirPath[1,5]
LOCAL lnF, lnI
*/ Include any Hidden or Directories...
lnF = ADIR( laOneDirPath, justOneDirectory + "*.*", "HD" )
FOR lnI = 1 TO lnF
INSERT INTO C_DirWalk;
( justThePath,;
TheFile,;
TheSize,;
TheDate,;
TheTime,;
TheFlags );
values;
( justOneDirectory,;
laOneDirPath[ lnI, 1],;
laOneDirPath[ lnI, 2],;
laOneDirPath[ lnI, 3],;
laOneDirPath[ lnI, 4],;
laOneDirPath[ lnI, 5] )
*/ If this was a directory, make a recursive call but tacking on
*/ this path... but do NOT process directories that are
*/ the "." (same directory) or ".." (parent)
IF "D" $ laOneDirPath[ lnI, 5] ;
AND LEN( CHRTRAN( laOneDirPath[ lnI, 1], ".", "" )) > 0
*/ Yes, a valid path OTHER than just "." or ".."
WalkTheDir( justOneDirectory + laOneDirPath[ lnI, 1] )
ENDIF
ENDFOR
ENDPROC