如合再给定的一个文件夹下查找有多少个文件夹(50分)

  • 主题发起人 主题发起人 fossil
  • 开始时间 开始时间
F

fossil

Unregistered / Unconfirmed
GUEST, unregistred user!
如合再给定的一个文件夹下查找有多少个文件夹
 
function SlashSep(const Path, S: String): String;
begin
if AnsiLastChar(Path)^ <> '/' then

Result := Path + '/' + S
else
Result := Path + S;
end;

function ReadDirectoryNames(const ParentDirectory: string;const DirType:string;
DirectoryList: TStringList): Integer;
var
Status: Integer;
SearchRec: TSearchRec;
begin
Result := 0;
Status := FindFirst(SlashSep(ParentDirectory, DirType), faDirectory, SearchRec);
try
while Status = 0 do
begin
if ((SearchRec.Attr and faDirectory) = faDirectory) then
begin
if (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then
begin
DirectoryList.Add(SearchRec.Name);
Inc(Result);
end;
end;
Status := FindNext(SearchRec);
end;
finally
SysUtils.FindClose(SearchRec);
end;
end;
 
function ReadDirectoryNames(const ParentDirectory: string;const DirType:string;
DirectoryList: TStringList): Integer;
这几个变量逗代表什么意思啊?
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
DirectoryList: TMemo;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}


procedure TForm1.Button1Click(Sender: TObject);
var
S: String;
i: Integer;
DirectoryList: TStringList;

function SlashSep(const Path, S: String): String;
begin
if AnsiLastChar(Path)^ <> '/' then

Result := Path + '/' + S
else
Result := Path + S;
end;

function ReadDirectoryNames(const ParentDirectory: string;const DirType:string;
DirectoryList: TStringList): Integer;
var
Status: Integer;
SearchRec: TSearchRec;
begin
Result := 0;
Status := FindFirst(SlashSep(ParentDirectory, DirType), faDirectory, SearchRec);
try
while Status = 0 do
begin
if ((SearchRec.Attr and faDirectory) = faDirectory) then
begin
if (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then
begin
DirectoryList.Add(SearchRec.Name);
Inc(Result);
end;
end;
Status := FindNext(SearchRec);
end;
finally
SysUtils.FindClose(SearchRec);
end;
end;

begin
i:= ReadDirectoryNames('D:/系统/FCHWASystem/Modules/考勤数据导入','*.*',DirectoryList);
Edit1.Text := inttostr(i);
end;

end.
有时候运行回报错 Access vilation at adress 004295CC in module'project1.exe'write of adrress 0042910
这是怎么回事情,一会有好了,但是单击可执行文件,又会保同样的错误
 
接受答案了.
 
啊???,你居然不create TStringList.,
 
后退
顶部