获取指定文件的创建时间应该怎么写
是这么写的么FILETIMEtime;FILETIMEzhuan;LPSYSTEMTIMEaa;time=td.ftCreationTime;GetSystemTimeA...
是这么写的么
FILETIME time;
FILETIME zhuan;
LPSYSTEMTIME aa;
time=td.ftCreationTime;
GetSystemTimeAsFileTime(&zhuan);
FileTimeToLocalFileTime(&time,&zhuan);
FileTimeToSystemTime(&zhuan,aa); 展开
FILETIME time;
FILETIME zhuan;
LPSYSTEMTIME aa;
time=td.ftCreationTime;
GetSystemTimeAsFileTime(&zhuan);
FileTimeToLocalFileTime(&time,&zhuan);
FileTimeToSystemTime(&zhuan,aa); 展开
1个回答
展开全部
以下是获得文件创建时间的代码,写入数据库就自己写吧,上一个问题已经说了怎么写数据库,我就不写代码了。
function TForm1.FileCreateTime(AFile: String): TDateTime;
var
hFile : THandle;
ST : TSystemTime;
lpCreationTime, lpLastAccessTime, lpLastWriteTime: TFileTime;
begin
try
if not FileExists(AFile) then Exit;
hFile := FileOpen(AFile, fmOpenWrite or fmShareDenyNone);
GetFileTime(hFile, @lpCreationTime, @lpLastAccessTime, @lpLastWriteTime);
//CreationTime 获得创建时间
FileTimeToLocalFileTime(lpCreationTime, lpCreationTime);
FileTimeToSystemTime(lpCreationTime, ST);
Result := SystemTimeToDateTime(ST);
{ //LastAccessTime 获得最后访问时间
FileTimeToLocalFileTime(lpLastAccessTime, lpLastAccessTime);
FileTimeToSystemTime(lpLastAccessTime, ST);
AoLastAccessTime := SystemTimeToDateTime(ST);
//LastWriteTime 获得最后修改时间
FileTimeToLocalFileTime(lpLastWriteTime, lpLastWriteTime);
FileTimeToSystemTime(lpLastWriteTime, ST);
AoLastWriteTime := SystemTimeToDateTime(ST); }
FileClose(hFile);
except
end;
end;
function TForm1.FileCreateTime(AFile: String): TDateTime;
var
hFile : THandle;
ST : TSystemTime;
lpCreationTime, lpLastAccessTime, lpLastWriteTime: TFileTime;
begin
try
if not FileExists(AFile) then Exit;
hFile := FileOpen(AFile, fmOpenWrite or fmShareDenyNone);
GetFileTime(hFile, @lpCreationTime, @lpLastAccessTime, @lpLastWriteTime);
//CreationTime 获得创建时间
FileTimeToLocalFileTime(lpCreationTime, lpCreationTime);
FileTimeToSystemTime(lpCreationTime, ST);
Result := SystemTimeToDateTime(ST);
{ //LastAccessTime 获得最后访问时间
FileTimeToLocalFileTime(lpLastAccessTime, lpLastAccessTime);
FileTimeToSystemTime(lpLastAccessTime, ST);
AoLastAccessTime := SystemTimeToDateTime(ST);
//LastWriteTime 获得最后修改时间
FileTimeToLocalFileTime(lpLastWriteTime, lpLastWriteTime);
FileTimeToSystemTime(lpLastWriteTime, ST);
AoLastWriteTime := SystemTimeToDateTime(ST); }
FileClose(hFile);
except
end;
end;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询