powerbuilder12.5在windows7底下怎么获取文件的创建时间。
对应的api我也调用了,还是不行。搞了好久还是不行,在线等啊。
openfile
GetFileTime
FileTimeToLocalFileTime
FileTimeToLocalFileTime
网上参考的代码:
type FileTime from structure
long dwLowDateTime
long dwHighDateTime
end type
type OFSTRUCT from structure
unsignedinteger cBytes
unsignedinteger fFixedDisk
integer nErrCode
integer Reserved1
integer Reserved2
integer szPathName[128]
end type
type systemtime from structure
integer wYear
integer wMonth
integer wDayOfWeek
integer wDay
integer wHour
integer wMinute
integer wSecond
integer wMilliseconds
end type
定义API函数
FUNCTION ulong GetFileTime(ulong hFile,ref FILETIME lpCreationTime,ref FILETIME lpLastAccessTime,ref FILETIME lpLastWriteTime) LIBRARY "kernel32.dll"
FUNCTION ulong OpenFile(ref string lpFileName,ref OFSTRUCT lpReOpenBuff,ulong wStyle) LIBRARY "kernel32.dll" Alias For "OpenFile;Ansi"
FUNCTION ulong FileTimeToSystemTime(ref FILETIME lpFileTime,ref SYSTEMTIME lpSystemTime) LIBRARY "kernel32.dll"
Function ulong FileTimeToLocalFileTime(ref FILETIME lpFileTime ,ref FILETIME lpLocalFileTime ) LIBRARY "kernel32.dll"
函数
参数
public function datetime of_getfiletime (string as_filename, integer ai_flag);ulong lul_hFile
datetime ldt_time
string ls_time
ofstruct lst_ofstruct
systemtime lst_systemtime
filetime lst_filetime1,lst_filetime2,lst_filetime3,lst_filetime//分别是创建时间、访问时间、修改时间
if ai_flag < 1 or ai_flag > 3 then ai_flag = 3
lul_hFile = openfile(as_filename,lst_ofstruct,0)//取句柄
GetFileTime(lul_hFile,lst_filetime1,lst_filetime2,lst_filetime3)//取时间
choose case ai_flag //将UTC格式转化成系统时间格式
case 1//创建时间
// FileTimeToSystemTime(LST_FileTime1,LST_SYSTEMTIME)
FileTimeToLocalFileTime(LST_FileTime1,lst_filetime)
case 2//访问时间
// FileTimeToSystemTime(LST_FileTime2,LST_SYSTEMTIME)
FileTimeToLocalFileTime(LST_FileTime2,lst_filetime)
case 3//修改时间
// FileTimeToSystemTime(LST_FileTime3,LST_SYSTEMTIME)
FileTimeToLocalFileTime(LST_FileTime3,lst_filetime)
end choose
FileTimeToSystemTime(lst_filetime,LST_SYSTEMTIME)
ls_time = string(lst_systemtime.wYear,'0000')+ '-'+string(lst_systemtime.wMonth,'00') + '-'+string(lst_systemtime.wDay,'00')+' '
ls_time += string(lst_systemtime.wHour,'00')+ ':'+string(lst_systemtime.wMinute,'00') + ':'+string(lst_systemtime.wSecond,'00')
ldt_time = m0_f_datetime(ls_time) //m0_f_开头的函数为我MBASE (MIS BASE FRAMEWORK)的基础函数,转换为时间
return ldt_time
end function
------解决方案--------------------
oleobject lole_f, lole_file