Places information about files into an array and then returns the number of files.
Syntax
ADIR(ArrayName [, cFileSkeleton [, cAttribute]])
Returns
Numeric
Arguments
ArrayName
Specifies the name of the array. If the array you include doesn't exist, Visual FoxPro automatically creates the array. If the array exists and isn't large enough to contain all the information, Visual FoxPro automatically increases the size of the array to accommodate the information. If the array is larger than necessary, Visual FoxPro truncates the array. If the array exists and ADIR( ) returns 0 because no matching files are found, the array remains unchanged. If the array doesn't exist and ADIR( ) returns 0, the array isn't created.
The following table describes the contents and data type of each column in the array:
Column Array contents Data type
1 File names Character
2 File sizes Numeric
3 Dates last modified Date
4 Times last modified Character
5 File attributes Character
The last array column contains the file attributes of the matching files. Each file attribute is expressed by a letter; a file can have more than one attribute. The following table indicates the file attribute represented by each letter:
Letter Attribute
A Archive – Read/Write
H Hidden
R Read-only
S System
D Directory
cFileSkeleton
Specifies a file skeleton so you can store information about files with names or extensions that match a search criterion. For example, the criterion can be all tables, all text files, all files with names that have A as their first letter, and so on. Such general searches are done by including the wildcards * and ? in cFileSkeleton. A question mark represents a single character; an asterisk represents any number of characters. You can use any number of wildcards in any position within the file skeleton.
You can specify a drive and/or directory to search in for matching file names. If you don't specify a drive and directory, Visual FoxPro places information about files in the current directory into the array.
cAttribute
Specifies the inclusion of subdirectories and hidden or system files.
cAttribute can contain any combination of D, H, and S. Including D returns subdirectory names of the current directory in addition to file names that match the file skeleton specified in cFileSkeleton. Including H returns information about hidden files that match the file skeleton specified in cFileSkeleton. Including S returns information about system files that match the file skeleton specified in cFileSkeleton.
Include an empty string in cFileSkeleton to return just subdirectory names, hidden files or system files.
You can include V in cAttribute to return the volume name of the current drive. Only the volume name is returned to the array if V is included with D, H, or S. The volume name is stored in the first array element and the remainder of the array is truncated.
Remarks
For each file, ADIR( ) places into the array the file name, size, date last modified, time last modified, and attributes.
*******用于遍历当前目录下的所有子目录,并以数据表的形式返回所有子目录
*******参数:cDrivePath 用于统计的当前目录
*******参数:dbfDirIndex 程序返回的目录表
*******参数:nDirCount 用于存诸遍历所得到的目录数目
PROCEDURE GetAllDir
Parameters cDrivePath,cDirIndexDBF
cDrivePath='C:' &&需扫描的盘符
use
Create Cursor dbfDirIndex (wjmc c(120),wjcd n(10),wjrq d,wjshj c(10),wjsx c(6))
xGS=1
xCD=0
append BLANK
REPL wjmc WITH cDrivePath
do while !eof()
nRecn=Recn()
cDrivePath=allt(wjmc)+'\'
x=adir(Mysz,(cDrivePath+'*.*'),'rashd')
* thisform.label1.caption="正在处理:"+alltrim(cDrivePath)
if x<>0
for I=3 to x
Mysz(I,1)=cDrivePath+Mysz(I,1)
xGS=xGS+1
xCD=xCD+Mysz(I,2)
endf
append from array Mysz for allt(wjmc)<>'.' AND allt(wjmc)<>'..' and 'D'$wjsx
endi
go nRecn
skip
endd
sele dbfDirIndex
nDirCount=reccount()
*brow
*use
return