如何获取95文件的时间信息(35分)

  • 主题发起人 主题发起人 陈冲伟
  • 开始时间 开始时间

陈冲伟

Unregistered / Unconfirmed
GUEST, unregistred user!
文件的创建时间,文件的最后访问时间和文件的最后修改时间。
 
看看这个:(Widows API)
GetFileTime
The GetFileTime function retrieves the date and time that a file was created, last accessed,
and last modified.
BOOL GetFileTime(
HANDLE hFile, // handle to the file
LPFILETIME lpCreationTime, // address of creation time
LPFILETIME lpLastAccessTime, // address of last access time
LPFILETIME lpLastWriteTime // address of last write time
);

Parameters
hFile
Handle to the files for which to get dates and times. The file handle must have been created
with GENERIC_READ access to the file.
lpCreationTime
Pointer to a FILETIME structure to receive the date and time the file was created. This parameter
can be NULL if the applicationdo
es not require this information.
lpLastAccessTime
Pointer to a FILETIME structure to receive the date and time the file was last accessed. The last
access time includes the last time the file was written to, read from, or, in the case of executable files, run. This parameter can be NULL if the application
does not require this information.
lpLastWriteTime
Pointer to a FILETIME structure to receive the date and time the file was last written to.
This parameter can be NULL if the applicationdo
es not require this information.
Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information,
call GetLastError.
Remarks
The FAT and NTFS file systems support the file creation, last access, and last write
time values.
Windows 95: The precision of the time for a file in a FAT file system is 2 seconds.
The time precision for files in other file systems, such as those connected through
a network depends on the file system but may also be limited by the remote device.
QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Requires version 1.0 or later.
Header: Declared in winbase.h.
Import Library: Use kernel32.lib.
See Also
Time Overview, Time Functions, FILETIME, GetFileSize, GetFileType, SetFileTime
 
FileDateTime;
 
哇,茶叶蛋,你好快呀.
 
hehe,茶叶蛋兄:
你贴的那段SDK帮助我当然已经看过了,问题是用GetFileTime获取的时间是
放在FILETIME结构中的。如何才能把它转化为普通的字符串形式呢?我定义了
a: FILETIME;
b;
SYSTEMTIME:
而后用FileTimeToSystemTime函数 FileTimeToSystemTime(@a, @b),但是编译器
总是说类型不兼容。
 
procedure TForm1.Button1Click(Sender: TObject);
var
FileHandle : Integer;
time : TFileTime;
time1, time2 : TFileTime;
data : Tdatetime;
ti : TSystemtime;
begin
if Open.execute then
begin
FileHandle := FileOPen( Open.FileName, fmOpenRead ) ;
GetFileTime( FileHandle, @time, @time1, @time2 );
FileTimeToSystemTime( time, ti );
data := SystemTimeToDateTime( ti );
showmessage( Datetimetostr( data ) );
end;
end;

搞定了。
这样做应该有效了。
Delphi中的FileTimeToSystemTime函数好像和SDK中的不一样? :-)
正确的传递参数应该是: FileTimeToSystemTime( time, ti );
(不好意思,昨天没有注意这个问题)
 
unction GetFileDate(TheFileName: string): string;
var
FHandle: integer;
begin
FHandle := FileOpen(TheFileName, 0);
try
Result := DateTimeToStr(FileDateToDateTime(FileGetDate(FHandle)));
finally
FileClose(FHandle);
end;
end;


 
我用Delphi的DateTimeToStr()显示出来的是yyyy-mm-dd格式的日期,如何才能
显示象中文95/NT中文件属性的本地化(中文)的时间格式呢?
 
用formatdatetime....
提这么多问题,分不能多加点吗? :--D
 
我想FormatDateTime也许并不是本地化程序的一种好方法吧,你在中文平台下
得到了正确的显示,而在英文平台下也许就会出问题。
 
多人接受答案了。
 
后退
顶部