急!如何获取指定目录下所有文件和目录名称列表

hxcj 2003-01-09 08:09:48
如果我想得到指定目录下的文件和目录甚至是子目录下的文件和目录名称列表清单,用什么方式可以实现?用dir等命令只能获得当前目录下的文件名列表,且不是按行排列!
如果可能用控件也可以,但是VFP的类似控件似乎功能太少了
...全文
222 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
hax123 2003-01-09
  • 打赏
  • 举报
回复
你拿那个的目的是什么呢,
用getfile()就可以拿到你要的文件
marki 2003-01-09
  • 打赏
  • 举报
回复
ADIR( ) Function
Example See Also

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.
gosea 2003-01-09
  • 打赏
  • 举报
回复
*******用于遍历当前目录下的所有子目录,并以数据表的形式返回所有子目录
*******参数: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

2,748

社区成员

发帖
与我相关
我的任务
社区描述
VFP,是Microsoft公司推出的数据库开发软件,用它来开发数据库,既简单又方便。
社区管理员
  • VFP社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧