PB中需要讀取檔案的修改時間,但目前版本不提供相關函數,可以使用API達到此目的,可以将API封裝起來,供調用。
定義結構
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"
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