这个代码上小弟我赋值改赋点什么
这个代码上我赋值改赋点什么
srcFileName这两个要赋值我不知道赋些什么
------解决思路----------------------
srcPath
srcFileName这两个要赋值,一个是指定的文件路径,一个是指定的文件名,统计文件个数GetFileCount
------解决思路----------------------
按上述代码修正,即可。
你的错误:
function GetFileCount(srcPath, srcFileName: string): Integer;
定义在FormCreat事件 中,
Button事件是不能调用的。
修正:
你应该将它拉出来,放在
private
或
public
{ Public declarati
就可以了。代码我已经编译通过。
interfacesrcPath
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Label1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
function GetFileCount(srcPath, srcFileName: string): Integer;
var
FileRec: TSearchrec;
currPath: string;
begin
if srcPath[Length(srcPath)] <> '\' then srcPath := srcPath + '\';
currPath := srcPath + '*.*';
Result := 0;
if FindFirst(currPath, faAnyFile, FileRec) = 0 then
repeat
if ((FileRec.Attr and faDirectory) <> 0) and
(FileRec.Name <> '.') and
(FileRec.Name <> '..') then
begin
Result := Result + GetFileCount(srcPath + FileRec.Name, srcFileName);
end else
if AnsiCompareText(srcFileName, FileRec.Name) = 0 then
Result := Result + 1;
until FindNext(FileRec) <> 0;
end;
begin
end;
procedure TForm1.Button1Click(Sender: TObject);
srcPath:='C:\'
srcFileName:='file.txt'
begin
GetFileCount(srcPath, srcFileName )
end;
srcFileName这两个要赋值我不知道赋些什么
------解决思路----------------------
srcPath
srcFileName这两个要赋值,一个是指定的文件路径,一个是指定的文件名,统计文件个数GetFileCount
------解决思路----------------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function GetFileCount(srcPath, srcFileName: string): Integer;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.GetFileCount(srcPath, srcFileName: string): Integer;
var FileRec: TSearchrec;
currPath: string;
begin
if srcPath[Length(srcPath)] <> '\' then srcPath := srcPath + '\';
currPath := srcPath + '*.*';
Result := 0;
if FindFirst(currPath, faAnyFile, FileRec) = 0 then
repeat
if ((FileRec.Attr and faDirectory) <> 0) and
(FileRec.Name <> '.') and
(FileRec.Name <> '..') then
begin
Result := Result + GetFileCount(srcPath + FileRec.Name, srcFileName);
end
else
if AnsiCompareText(srcFileName, FileRec.Name) = 0 then
Result := Result + 1;
until FindNext(FileRec) <> 0;
end;
procedure TForm1.Button1Click(Sender: TObject);
var n:integer;
begin
n:=GetFileCount('c:\', 'cmd.exe');
showmessage('有'+inttostr(n)+'个同名文件');
end;
end.
按上述代码修正,即可。
你的错误:
function GetFileCount(srcPath, srcFileName: string): Integer;
定义在FormCreat事件 中,
Button事件是不能调用的。
修正:
你应该将它拉出来,放在
private
或
public
{ Public declarati
就可以了。代码我已经编译通过。