如何在中取得文件的时间(创建时间、修改时间)?

arich 2002-08-30 05:04:46
如何在中取得文件的时间(创建时间、修改时间)?
...全文
95 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
killerdanny 2002-08-30
  • 打赏
  • 举报
回复
API:

Function long CreateFile (ref string lpFileName, ulong dwDesiredAccess, ulong dwShareMode, ulong lpSecurityAttributes, ulong dwCreationDisposition, ulong dwFlagsAndAttributes, ulong hTemplateFile) Library "KERNEL32.DLL" Alias for "CreateFileA"

Function boolean GetFileTime (ulong hFile, ref FILETIME lpCreationTime, ref FILETIME lpLastAccessTime, ref FILETIME lpLastWriteTime ) Library "KERNEL32.DLL"

Function Boolean CloseHandle ( long hObject) Library "KERNEL32.DLL"
killerdanny 2002-08-30
  • 打赏
  • 举报
回复
type FileTime from structure
ulong LowDateTime
ulong HighDateTime
end type

///////////////////////////////////////////
type OPENFILENAME from structure
long lstructsize
long hwndowner
long hinstance
long lpstrfilter
long lpstrcustomfilter
long nMaxCustomFilter
long nFilterIndex
long lpstrFile
long nMaxFile
long lpstrFileTitle
long nMaxFileTitle
long lpstrInitialDir
long lpstrTitle
long Flags
integer nFileOffset
integer nFileExtension
long lpstrDefExt
long lCustData
long lpfnHook
long lpTemplateName
end type
/////////////////////////////////////////////

type BY_HANDLE_FILE_INFORMATION from structure
unsignedlong dwFileAttributes
unsignedlong dwLowDateTime_creation
unsignedlong dwHighDateTime_creation
unsignedlong dwLowDateTime_lastaccess
unsignedlong dwHighDateTime_lastaccess
unsignedlong dwLowDateTime_lastwrite
unsignedlong dwHighDateTime_lastwrite
unsignedlong dwVolumeSerialNumber
unsignedlong nFileSizeHigh
unsignedlong nFileSizeLow
unsignedlong nNumberOfLinks
unsignedlong nFileIndexHigh
unsignedlong nFileIndexLow
end type
////////////////////////////////////////////////////////////
CONSTANT LONG GENERIC_READ = 2147483648
CONSTANT LONG GENERIC_WRITE = 1073741824
CONSTANT LONG CREATE_NEW = 1
CONSTANT LONG CREATE_ALWAYS = 2
CONSTANT LONG OPEN_EXISTING = 3
CONSTANT LONG OPEN_ALWAYS=4
CONSTANT LONG FILE_SHARE_READ=1
CONSTANT LONG FILE_SHARE_WRITE=2
CONSTANT LONG FILE_FLAG_RANDOM_ACCESS = 268435456
CONSTANT LONG MAXDWORD=65535
/////////////////////////////////////////////////////////////
public function integer of_comparefiletime (string file1, string file2);//// 比较文件时间,-1 file1早;0 file1=file2;1 file1晚 else出错
long FileHandle1,FileHandle2;
long rtn;
FILETIME lpCreationTime,lpLastAccessTime,FileTime1,FileTime2
Boolean brtn1,brtn2;
//////////
FileHandle1 = createfile( File1, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, 0 )
FileHandle2 = createfile( File2, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, 0 )

if FileHandle1 > 0 and FileHandle2 > 0 then
// 检查文件日期
brtn1 = GetFileTime( FileHandle1, lpCreationTime, lpLastAccessTime, FileTime1 )
brtn2 = GetFileTime( FileHandle2, lpCreationTime, lpLastAccessTime, FileTime2 )
if brtn1 and brtn2 then
rtn = CompareFileTime(FileTime1,FileTime2)
else
rtn = -200;
end if
else
rtn = -100;
end if
if FileHandle1>0 then of_closeFile(FileHandle1);
if FileHandle2>0 then of_closeFile(FileHandle2);
return rtn;
end function
///////////////////////////////////////////////////////
public function boolean of_closefile (long fhandle);
Boolean ret

ret = closehandle( fhandle )
if ret = false then
of_showwindowerror()
end if
return ret

end function

1,072

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧