unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(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;
srcPath: string;
srcFileName: string;
Result: integer;
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;
end.
uj5u.com熱心網友回復:
大神 可以在自己電腦上運行下,看看那里有錯誤,我自己運行到Var變數srcPath: string;那里就有錯誤了uj5u.com熱心網友回復:
求師傅幫幫忙啊uj5u.com熱心網友回復:
unit Unit1;interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
procedure FormCreate(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;
// srcPath: string; 這三個不要
// srcFileName: string;
// Result: integer;
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 //這里加上begin end 即可
end;
end.
uj5u.com熱心網友回復:
謝謝!!!!!!!uj5u.com熱心網友回復:
//該處代碼用于求出指定路徑下具有相同檔案名的檔案個數這個程式表單上應該添加點什么
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
pFR: PFileRecord;
iCount: Integer;
begin
if slFileResult = nil then
slFileResult := TStringList.Create;
Caption := IntToStr(GetFileCount(Edit1.Text));
for i := 0 to slFileResult.Count - 1 do
begin
pFR := PFileRecord(slFileResult.Objects[i]);
if pFR.iCount > 1 then
begin
iCount := iCount + 1;
Memo1.Lines.Add(Format('%d----%s', [pFR.iCount, pFR.sFilename]));
end;
end;
Caption := IntToStr(iCount);
end;
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/91705.html
標籤:語言基礎/算法/系統設計
下一篇:advstringgrid 滾輪
