关于目录下文件的提取问题

jeffy56 2003-08-21 01:43:32
请问各位高手,如何返回指定目录下文件的个数和文件名?急用,请高手速复!谢谢
...全文
30 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jeffy56 2003-08-21
  • 打赏
  • 举报
回复
多谢二位!
boomit 2003-08-21
  • 打赏
  • 举报
回复
ADIR( ) 函数
示例 请参阅

将文件信息存放到数组中,然后返回文件个数。
语法
ADIR(ArrayName [, cFileSkeleton [, cAttribute [, cCreatorType]]])
参数
ArrayName

指定数组名。如果数组不存在,Visual FoxPro 将自动创建此数组。如果数组存在,但其大小不足以包含所有信息,则 Visual FoxPro 自动增加数组大小,使得数组能容纳所有信息。如果数组超过了所需大小,Visual FoxPro 将截掉多余部分。如果数组存在,并且 ADIR( ) 函数由于没找到匹配文件而返回 0,则数组保持不变。如果数组不存在,并且 ADIR( ) 函数返回零,则不创建数组。

下表说明了数组中每列的内容及其数据类型:

列 数组内容 数据类型
1 文件名 字符型
2 文件大小 数值型
3 文件最后修改日期 日期型
4 文件最后修改时间 字符型
5 文件属性 字符型

数组的最后一列包含匹配文件的文件属性。每个文件属性值由一个字母表示,一个文件可有多个属性。下表说明每个字母表示的文件属性含义:

字母 属性
A 档案文件 一 可读写
H 隐藏文件
R 只读文件
S 系统文件
D 目录或文件夹

cFileSkeleton

指定文件梗概,以便存储满足搜索条件的文件名或扩展名的文件信息。例如,条件可以是所有表、所有文本文件、所有文件名第一个字母为“A”的文件,等等。这些通配查询在 cFileSkeleton 中可以包含通配符 * 和 ?。其中问号代表单个字符,星号代表任意字符串。在文件梗概中,可在任意位置使用任意个数的通配符。
在 Visual FoxPro、FoxPro for Windows 和 FoxPro for MS-DOS 中,可以指定驱动器和目录名,程序将在此驱动器和目录下搜索匹配文件。如果不指定驱动器和目录名,将把当前目录下的文件信息存入数组中。

在 FoxPro for Macintosh 中,可以搜索匹配文件名的卷和文件夹。如果不指定卷和文件夹,
FoxPro for Macintosh 将当前文件夹中的文件信息存入数组中。

cAttribute

指定在返回内容中包含子目录或嵌套文件夹、隐藏或系统文件、或者卷名。
cAttribute 可以是 D、H 和 S 的任意组合。如果包含 D,除了返回匹配 cFileSkeleton 的文件名外,还将返回当前目录的子目录或当前文件夹的嵌套文件夹。如果包含 H,将返回与 cFileSkeleton 指定相匹配的隐藏文件信息。如果包含 S,将返回与 cFileSkeleton 指定通配文件名相匹配的系统文件信息。
如果 cFileSkeleton 为空字符串,仅返回子目录或嵌套文件夹名、隐藏或系统文件。

cAttribute 参数中包含字符 V,将返回当前驱动器的卷名。如果 V 和 D、H 或 S 一起包含在数组中,则只返回卷名。卷名存入数组的第一个元素中,并截去数组的其余部分。

cCreatorType

仅用于 FoxPro for Macintosh。
用指定的创建程序类型指定文件。如果参数 cFileSkeleton 为空字符串,则仅有匹配指定创建程序类型 cCreatorType 的文件放置到数组中去。如果在参数 cfileSkeleton 中有一个文件梗概,则匹配文件梗概且具有 cCreatorType 指定的创建程序类型的文件被放入数组中。
若要获取 FoxPro for Macintosh 所有的文件扩展名以及相关的创建程序类型,请参阅文件扩展名与文件类型。
返回值类型
数值型
说明
对于每一个文件,ADIR( ) 将文件名、大小、日期、时间和属性信息存入数组。
magnetmoon 2003-08-21
  • 打赏
  • 举报
回复
n=adir(lal_array,'d:\downvfp\*.*')
?n
for i=1 to n
?lal_array(i,1)
endfor



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 exist, Visual FoxPro automatically creates the array. If the array exists and isn 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 exist and ADIR( ) returns 0, the array isn 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 or folder
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 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.

Remarks
For each file, ADIR( ) places into the array the file name, size, date last modified, time last modified, and attributes.

2,722

社区成员

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

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