如何读取文件的创建时间(注意是创建时期加时间)和文件大小?
有那为大哥能给个完整的例子谢谢!
有那为大哥能给个完整的例子谢谢!
解决方案 »
- XLSReadWriteII 导出EXCEL 怎么设列宽度
- 散
- 如何在Delphi中解析XML的脚本?结帐很快的!
- 怎么在字符串列表中假如图片?Tlistbox?
- =====请教一个关于文件操作的问题=====
- 如何在delphi中安装windows的MediaPlay控件(msdxm.ocx)?
- 请教各位delphi大侠,打印及简单导入Excel
- 在TORBO PASCAL6.0下如何把图形驱动静态连接到程序中?
- 怎样获取DBGRID中鼠标点中的单元格的行号,列号和内容?
- 在线等候高手指点:这条sql语句怎么写?
- 如何读取文件的创建时间和文件大小?
- 请教-------------为什么我的ScrollBox 不显示滚动条?
var
Tp:TSearchRec;
begin
FindFirst(Filename,faAnyFile,Tp);
Result:=FormatDateTime('yyyy/mm/dd,hh:mm:ss',CovFileDate(Tp.FindData.ftCreationTime));
FindClose(Tp);
end;function GetDirectorySize(const ADirectory:string):Integer;
var
sr:TSearchRec;
begin
Result:=0;
if not DirectoryExists(ADirectory) then exit;
if FindFirst(ADirectory+'\*.*', faAnyFile, sr) = 0 then
begin
repeat
if ((sr.Attr and faDirectory)=faDirectory) and(sr.Name<>'.') and (sr.Name<>'..') then begin
Result:=Result+GetDirectorySize(ADirectory+'\'+sr.Name) ;
end else if (sr.Name <>'.') and (sr.Name<>'..') then begin
Result:=Result+sr.Size;
end;
until FindNext(sr) <> 0;
FindClose(sr);
end;
end;
var
Tct:SystemTime;
Temp:FileTime;
begin
FileTimeToLocalFileTime(Fd,Temp);
FileTimeToSystemTime(Temp,Tct);
CovFileDate:=SystemTimeToDateTime(Tct);
end;
少了一个
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
function GetFileCreateDT(filename:string):string;//获得文件创建日期和时间
function CovFileDate(Fd:_FileTime):TDateTime;//转换日期时间格式
function GetFileSizeValue(pFilePath:string):Int64; //文件大小
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}function TForm1.CovFileDate(Fd: _FileTime): TDateTime;
var
Tct:_SystemTime;
Temp:_FileTime;
begin
FileTimeToLocalFileTime(Fd,Temp);
FileTimeToSystemTime(Temp,Tct);
CovFileDate:=SystemTimeToDateTime(Tct);
end;function TForm1.GetFileCreateDT(filename: string): string;
var Tp:TSearchRec;
begin
FindFirst(filename,faAnyFile,Tp);
Result:=FormatDateTime('YYYY-MM-DD,HH:MM:SS',CovFileDate(Tp.FindData.ftCreationTime));
end;procedure TForm1.Button1Click(Sender: TObject);
begin
Showmessage(GetFileCreateDT('D:\aa.rar'));
ShowMessage(IntToStr(GetFileSizeValue('D:\aa.rar')));
end;function TForm1.GetFileSizeValue(pFilePath: string): Int64;
var
hFile:Thandle;
dwSize,dwSizeHigh:DWORD;
begin
try
hFile:=CreateFile(pchar(pFilePath),GENERIC_READ,FILE_SHARE_READ,nil,OPEN_EXISTING,0,0);
dwSize:=GetFileSize(hFile,@dwSizeHigh);
CloseHandle(hFile);
Result:=dwSize;
except
Result:=0;
end;
end;end.
f: TSearchRec;
begin
if FindFirst(FileName, faAnyFile, f) = 0 then begin
FileSize := f.Size;
FileTime := f.Time;
FindClose(f);
end;
end;