如何取得一个文件夹中所有的文件的名称和修改时间呢? ( 积分: 50 )

  • 主题发起人 主题发起人 Ignorant
  • 开始时间 开始时间
I

Ignorant

Unregistered / Unconfirmed
GUEST, unregistred user!
我有个例子,你看看<br>unit Unit1;<br>interface<br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, ExtCtrls, StdCtrls, ComCtrls, TabNotBk, Buttons;<br>type<br> &nbsp;TfrmMain = class(TForm)<br> &nbsp; &nbsp;OpenDialog: TOpenDialog;<br> &nbsp; &nbsp;TabbedNotebook1: TTabbedNotebook;<br> &nbsp; &nbsp;Shape1: TShape;<br> &nbsp; &nbsp;Shape2: TShape;<br> &nbsp; &nbsp;BtnClose: TBitBtn;<br> &nbsp; &nbsp;Label1: TLabel;<br> &nbsp; &nbsp;ReadOnly: TCheckBox;<br> &nbsp; &nbsp;Hidden: TCheckBox;<br> &nbsp; &nbsp;Archive: TCheckBox;<br> &nbsp; &nbsp;System: TCheckBox;<br> &nbsp; &nbsp;lblPosition: TLabel;<br> &nbsp; &nbsp;lblSize: TLabel;<br> &nbsp; &nbsp;lblName: TLabel;<br> &nbsp; &nbsp;procedure FormCreate(Sender: TObject);<br> &nbsp; &nbsp;function GetFileSize(const FileName: string): LongInt;<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;frmMain: TfrmMain;<br> &nbsp;Attributes: Word;<br> &nbsp;NewAttributes: Word;<br> &nbsp;FileName:String;<br><br>implementation<br>{$R *.dfm}<br><br>procedure TfrmMain.FormCreate(Sender: TObject);<br>begin<br> &nbsp; &nbsp;if OpenDialog.Execute then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;FileName:= OpenDialog.FileName;<br> &nbsp; &nbsp; &nbsp; &nbsp;Attributes := FileGetAttr(FileName);<br> &nbsp; &nbsp; &nbsp; &nbsp;ReadOnly.Checked := (Attributes and faReadOnly) = faReadOnly;<br> &nbsp; &nbsp; &nbsp; &nbsp;Archive.Checked := (Attributes and faArchive) = faArchive;<br> &nbsp; &nbsp; &nbsp; &nbsp;System.Checked := (Attributes and faSysFile) = faSysFile;<br> &nbsp; &nbsp; &nbsp; &nbsp;Hidden.Checked := (Attributes and faHidden) = faHidden;<br><br> &nbsp; &nbsp; &nbsp; &nbsp;lblPosition.Caption:= lblPosition.Caption+ExtractFileDir(FileName);<br> &nbsp; &nbsp; &nbsp; &nbsp;lblName.Caption:=lblName.Caption+ExtractFileName(FileName);<br> &nbsp; &nbsp; &nbsp; &nbsp;lblSize.Caption:=lblSize.Caption+Format('%d bytes', [GetFileSize(FileName)]);<br> &nbsp; &nbsp;end;<br>end;<br><br>function TfrmMain.GetFileSize(const FileName: string): LongInt;<br>var<br> &nbsp;SearchRec: TSearchRec;<br>begin<br> &nbsp;try<br> &nbsp; &nbsp;if FindFirst(ExpandFileName(FileName), faAnyFile, SearchRec) = 0 then<br> &nbsp; &nbsp; &nbsp;Result := SearchRec.Size<br> &nbsp; &nbsp;else Result := -1;<br> &nbsp;finally<br> &nbsp; &nbsp;SysUtils.FindClose(SearchRec);<br> &nbsp;end;<br>end;<br><br>end.
 
后退
顶部