如何得到一个文件产生的日期(100分)

  • 主题发起人 主题发起人 zhang312
  • 开始时间 开始时间
Z

zhang312

Unregistered / Unconfirmed
GUEST, unregistred user!
如何得到一个文件产生的日期
如何把某个日期前产生的文件在filelistbox中全选中,以便copy or delete
 
// 取得文件创建时间
function GetFileCreationTime(const FileName: String): TDateTime;
var
FileTime: TFileTime;
LocalFileTime: TFileTime;
hFile: THandle;
SystemTime: TSystemTime;
begin
Result := 0;
FileTime.dwLowDateTime := 0;
FileTime.dwHighDateTime := 0;
hFile := FileOpen(FileName, fmShareDenyNone);
try
if hFile <> 0 then
begin
Windows.GetFileTime(hFile, @FileTime, nil, nil);
FileTimeToLocalFileTime(FileTime, LocalFileTime);
FileTime := LocalFileTime;
end;
finally
FileClose(hFile);
end;
if FileTimeToSystemTime(FileTime, SystemTime) then
Result := SystemTimeToDateTime(SystemTime);
end;
 
同意R_Baggio和Croco的话,我记得有一个Delph 3的帮助文件
事专门讲述Delphi对文件操作的,你自己找找,叫 Cat*.hlp??
 
直接用FindFirstFile不就都有了嘛. ^_^
 
如 何 得 到 文 件 的 创 建 日 期 和 时 间 ?
答 : 请 看 以 下 的 范 例 程 序
function GetFileDate(TheFileName: string): string;
var
FHandle: integer;
begin
FHandle := FileOpen(TheFileName, 0);
try
Result := DateTimeToStr(FileDateToDateTime(FileGetDate(FHandle)));
finally
FileClose(FHandle);
end;
end;
 
为什么不用 API 函数GetFileAttributesEx(),他将填充这样一个结构:

typedef struct _WIN32_FILE_ATTRIBUTE_DATA{
DWORD dwFileAttributes;
FILETIME ftCreationTime;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;
DWORD nFileSizeHigh;
DWORD nFileSizeLow;
}
足够了吧,详情参见MSDN.
 
The GetFileTime function retrieves the date and time that a file was created, last accessed, and last modified。
BOOL GetFileTime(

HANDLE hFile, // identifies the file
LPFILETIME lpCreationTime, // address of creation time
LPFILETIME lpLastAccessTime, // address of last access time
LPFILETIME lpLastWriteTime // address of last write time
);
-----------------------------------
The GetFileAttributesEx function obtains attribute information about a specified file or directory.
This function is similar to the GetFileAttributes function. GetFileAttributes returns a set of FAT-style attribute information. GetFileAttributesEx is designed to obtain other sets of file or directory attribute information. Currently, GetFileAttributeEx obtains a set of standard attributes that is a superset of the FAT-style attribute information.

BOOL GetFileAttributesEx(

LPCTSTR lpFileName, // pointer to string that specifies a file or directory
GET_FILEEX_INFO_LEVELS fInfoLevelId, // value that specifies the type of attribute information to obtain
LPVOID lpFileInformation // pointer to buffer to receive attribute information
);
 
多人接受答案了。
 
后退
顶部