永发信息网

用api函数中的getfiletime如何得到最后修改日期

答案:2  悬赏:0  手机版
解决时间 2021-02-19 15:23
  • 提问者网友:爱了却不能说
  • 2021-02-19 00:20
用api函数中的getfiletime如何得到最后修改日期
最佳答案
  • 五星知识达人网友:夜余生
  • 2021-02-19 00:47
比较两个文件日期的函数:
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 closehandle(filehandle1)
if filehandle2>0 then closehandle(filehandle2);
return rtn;

结构声明:
type filetime from structure
ulong lowdatetime
ulong highdatetime
end type

声明常量

constant integer max_path = 260
constant integer ofs_maxpathname = 128
public constant unsignedlong file_attribute_archive = 32
public constant unsignedlong file_attribute_compressed =2048
public constant unsignedlong file_attribute_directory = 16
public constant unsignedlong file_attribute_hidden = 2
public constant unsignedlong file_attribute_normal = 128
public constant unsignedlong file_attribute_readonly = 1
public constant unsignedlong file_attribute_system =4
public constant unsignedlong file_attribute_temporary =256
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

api声明:
function boolean closehandle ( long hobject) library "kernel32.dll"
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 long comparefiletime(ref filetime ft1,ref filetime ft2) library "kernel32.dll" alias for "comparefiletime"
function boolean getfiletime (ulong hfile, ref filetime lpcreationtime, ref filetime lplastaccesstime, ref filetime lplastwritetime ) library "kernel32.dll"

declare:
function boolean getfiledatetime(string lpfilename,uint nmode,ref string lpdate,ref string lptime) library "mhand.dll"

function:
para:
string as_filename
unsignedinteger ai_mode

script:
string ls_date,ls_time
datetime ldt_returnvalue

ls_date=space(10)
ls_time=space(8)

if not getfiledatetime(as_filename,ai_mode,ls_date,ls_time) then
setnull(ldt_returnvalue)
return ldt_returnvalue
end if

ldt_returnvalue=datetime(date(ls_date),time(ls_time))

return ldt_returnvalue
全部回答
  • 1楼网友:雾月
  • 2021-02-19 01:33
用api函数:GetFileTime ulong hfile long rtn filetime lpcreate filetime lpaccess filetime lpwrite hfile = FileOpen("odbc.ini") rtn = GetFileTime(hfile, lpcreate, lpaccess, lpwrite) Messagebox("File Handle", String(hfile)) Messagebox("Return Code", string(rtn)) FileClose(hfile)
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯