PB中如何取文件日期

global  type  uo_file_function  from  nonvisualobject  
end  type  
type  systemtime  from  structure  within  uo_file_function  
end  type  
type  filetime  from  structure  within  uo_file_function  
end  type  
type  security_attributes  from  structure  within  uo_file_function  
end  type  
 
type  SYSTEMTIME  from  structure    
unsignedinteger  wYear    
unsignedinteger  wMonth    
unsignedinteger  wDayOfWeek    
unsignedinteger  wDay    
unsignedinteger  wHour    
unsignedinteger  wMinute    
unsignedinteger  wSecond    
unsignedinteger  wMilliseconds    
end  type    
 
type  FILETIME  from  structure    
unsignedlong  dwLowDateTime    
unsignedlong  dwHighDateTime    
end  type    
 
type  SECURITY_ATTRIBUTES  from  structure    
unsignedlong  nLength    
unsignedlong  lpSecurityDescriptor    
boolean  bInheritHandle    
end  type    
 
global  type  uo_file_function  from  nonvisualobject  autoinstantiate  
end  type  
 
type  prototypes  
Private:    
Function  boolean  FileTimeToSystemTime(ref  FILETIME  lpFileTime,  ref  SYSTEMTIME  lpSystemTime)  Library  "kernel32.dll"    
Function  boolean  SystemTimeToFileTime(ref  SYSTEMTIME  lpSystemTime,  ref  FILETIME  lpFileTime)  Library  "kernel32.dll"    
Function  boolean  GetFileTime(ulong  hFile,  ref  FILETIME  lpCreationTime,ref  FILETIME  lpLastAccessTime,  ref  FILETIME  lpLastWriteTime)  Library  "kernel32.dll"    
Function  boolean  SetFileTime(ulong  hFile,  ref  FILETIME  lpCreationTime,ref  FILETIME  lpLastAccessTime,  ref  FILETIME  lpLastWriteTime)  Library  "kernel32.dll"    
Function  ulong  GetLastError()  Library  "kernel32.dll"    
Function  long  CreateFileA(ref  string  lpFileName,  ulong  dwDesiredAccess,  ulong  dwShareMode,ref  SECURITY_ATTRIBUTES  lpSecurityAttributes,  ulong  dwCreationDisposition,  ulong  dwFlagsAndAttributes,  ulong  hTemplateFile)  Library  "kernel32.dll"    
Function  boolean  FileTimeToLocalFileTime(ref  FILETIME  lpFileTime,  ref  FILETIME  lpLocalFileTime)  Library  "kernel32.dll"    
Function  boolean  LocalFileTimeToFileTime(ref  FILETIME  lpLocalFileTime,  ref  FILETIME  lpFileTime)  Library  "kernel32.dll"    
Function  boolean  CloseHandle(ulong  hObject)  Library  "kernel32.dll"    
 
end  prototypes  
type  variables  
constant  string  sDT_REMOVABLE  =  "REMOVABLE!"    
constant  string  sDT_FIXED  =  "FIXED!"    
constant  string  sDT_REMOTE  =  "REMOTE!"    
constant  string  sDT_CDROM  =  "CDROM!"    
constant  string  sDT_RAMDISK  =  "RAMDISK!"    
 
end  variables  
forward  prototypes  
public  function  boolean  of_file_get_times  (string  astr_pathname,  ref  datetime  adt_creationtime,  ref  datetime  adt_lastaccesstime,  ref  datetime  adt_lastwritetime)  
public  function  boolean  of_file_set_times  (string  astr_pathname,  datetime  adt_creationtime,  datetime  adt_lastaccesstime,  datetime  adt_lastwritetime)  
end  prototypes  
 
public  function  boolean  of_file_get_times  (string  astr_pathname,  ref  datetime  adt_creationtime,  ref  datetime  adt_lastaccesstime,  ref  datetime  adt_lastwritetime);constant  ulong  GENERIC_READ  =  2147483648    
constant  ulong  GENERIC_WRITE  =  1073741824    
constant  ulong  FILE_SHARE_READ  =  1    
constant  ulong  FILE_SHARE_WRITE  =  2    
constant  ulong  OPEN_EXISTING  =  3    
constant  ulong  FILE_ATTRIBUTE_ARCHIVE  =  32    
 
ulong  lul_Null;SetNull(lul_Null)    
 
long  ll_Handle,  ll_ErrorCode    
SECURITY_ATTRIBUTES  lsa_Temp    
FILETIME  lft_CreationTime,  lft_LastAccessTime,  lft_LastWriteTime,  lft_Temp    
SYSTEMTIME  lst_CreationTime,  lst_LastAccessTime,  lst_LastWriteTime    
 
lsa_Temp.nLength  =  12;    
lsa_Temp.lpSecurityDescriptor  =  lul_Null    
 
ll_Handle  =  CreateFileA(astr_PathName,  GENERIC_READ,  FILE_SHARE_READ  +  FILE_SHARE_WRITE,  lsa_Temp,  OPEN_EXISTING,  FILE_ATTRIBUTE_ARCHIVE,  lul_NULL)    
If  ll_Handle  <  1  Then  Return  False    
If  Not  GetFileTime(ll_Handle,  lft_CreationTime,  lft_LastAccessTime,  lft_LastWriteTime)  Then    
CloseHandle(ll_Handle)    
Return  False    
End  If    
CloseHandle(ll_Handle)    
 
If  Not  FileTimeToLocalFileTime(lft_CreationTime,  lft_Temp)  Then  Return  False    
If  Not  FileTimeToSystemTime(lft_Temp,  lst_CreationTime)  Then  Return  False    
 
If  Not  FileTimeToLocalFileTime(lft_LastAccessTime,  lft_Temp)  Then  Return  False    
If  Not  FileTimeToSystemTime(lft_Temp,  lst_LastAccessTime)  Then  Return  False    
If  Not  FileTimeToLocalFileTime(lft_LastWriteTime,  lft_Temp)  Then  Return  False    
If  Not  FileTimeToSystemTime(lft_Temp,  lst_LastWriteTime)  Then  Return  False    
 
adt_CreationTime  =  DateTime(Date(string(lst_CreationTime.wYear)  +  "-"  +  string(lst_CreationTime.wMonth)  +  "-"  +  string(lst_CreationTime.wDay)),  Time(string(lst_CreationTime.wHour)  +  ":"  +  string(lst_CreationTime.wMinute)  +  ":"  +  string(lst_CreationTime.wSecond)  +  ":"  +  string(lst_CreationTime.wMilliseconds)))    
adt_LastAccessTime  =  DateTime(Date(string(lst_LastAccessTime.wYear)  +  "-"  +  string(lst_LastAccessTime.wMonth)  +  "-"  +  string(lst_LastAccessTime.wDay)),  Time(string(lst_LastAccessTime.wHour)  +  ":"  +  string(lst_LastAccessTime.wMinute)  +  ":"  +  string(lst_LastAccessTime.wSecond)  +  ":"  +  string(lst_LastAccessTime.wMilliseconds)))    
adt_LastWriteTime  =  DateTime(Date(string(lst_LastWriteTime.wYear)  +  "-"  +  string(lst_LastWriteTime.wMonth)  +  "-"  +  string(lst_LastWriteTime.wDay)),  Time(string(lst_LastWriteTime.wHour)  +  ":"  +  string(lst_LastWriteTime.wMinute)  +  ":"  +  string(lst_LastWriteTime.wSecond)  +  ":"  +  string(lst_LastWriteTime.wMilliseconds)))    
 
Return  True    
 
end  function  
public  function  boolean  of_file_set_times  (string  astr_pathname,  datetime  adt_creationtime,  datetime  adt_lastaccesstime,  datetime  adt_lastwritetime);constant  ulong  GENERIC_READ  =  2147483648    
constant  ulong  GENERIC_WRITE  =  1073741824    
constant  ulong  FILE_SHARE_READ  =  1    
constant  ulong  FILE_SHARE_WRITE  =  2    
constant  ulong  OPEN_EXISTING  =  3    
constant  ulong  FILE_ATTRIBUTE_ARCHIVE  =  32    
 
ulong  lul_Null;SetNull(lul_Null)    
 
long  ll_Handle,  ll_ErrorCode    
SECURITY_ATTRIBUTES  lsa_Temp    
FILETIME  lft_CreationTime,  lft_LastAccessTime,  lft_LastWriteTime,  lft_Temp    
SYSTEMTIME  lst_CreationTime,  lst_LastAccessTime,  lst_LastWriteTime    
 
lsa_Temp.nLength  =  12;    
lsa_Temp.lpSecurityDescriptor  =  lul_Null    
 
lst_CreationTime.wYear  =  Year(Date(adt_CreationTime))    
lst_CreationTime.wMonth  =  Month(Date(adt_CreationTime))    
lst_CreationTime.wDayOfWeek  =  DayNumber(Date(adt_CreationTime))  -  1    
lst_CreationTime.wDay  =  Day(Date(adt_CreationTime))    
lst_CreationTime.wHour  =  Hour(Time(adt_CreationTime))    
lst_CreationTime.wMinute  =  Minute(Time(adt_CreationTime))    
lst_CreationTime.wSecond  =  Second(Time(adt_CreationTime))    
lst_CreationTime.wMilliseconds  =  0    
 
If  Not  SystemTimeToFileTime(lst_CreationTime,  lft_Temp)  Then  Return  False    
If  Not  LocalFileTimeToFileTime(lft_Temp,  lft_CreationTime)  Then  Return  False    
 
lst_LastAccessTime.wYear  =  Year(Date(adt_LastAccessTime))    
lst_LastAccessTime.wMonth  =  Month(Date(adt_LastAccessTime))    
lst_LastAccessTime.wDayOfWeek  =  DayNumber(Date(adt_LastAccessTime))  -  1    
lst_LastAccessTime.wDay  =  Day(Date(adt_LastAccessTime))    
lst_LastAccessTime.wHour  =  Hour(Time(adt_LastAccessTime))    
lst_LastAccessTime.wMinute  =  Minute(Time(adt_LastAccessTime))    
lst_LastAccessTime.wSecond  =  Second(Time(adt_LastAccessTime))    
lst_LastAccessTime.wMilliseconds  =  0    
 
If  Not  SystemTimeToFileTime(lst_LastAccessTime,  lft_Temp)  Then  Return  False    
If  Not  LocalFileTimeToFileTime(lft_Temp,  lft_LastAccessTime)  Then  Return  False    
 
lst_LastWriteTime.wYear  =  Year(Date(adt_LastWriteTime))    
lst_LastWriteTime.wMonth  =  Month(Date(adt_LastWriteTime))    
lst_LastWriteTime.wDayOfWeek  =  DayNumber(Date(adt_LastWriteTime))  -  1    
lst_LastWriteTime.wDay  =  Day(Date(adt_LastWriteTime))    
lst_LastWriteTime.wHour  =  Hour(Time(adt_LastWriteTime))    
lst_LastWriteTime.wMinute  =  Minute(Time(adt_LastWriteTime))    
lst_LastWriteTime.wSecond  =  Second(Time(adt_LastWriteTime))    
lst_LastWriteTime.wMilliseconds  =  0    
 
If  Not  SystemTimeToFileTime(lst_LastWriteTime,  lft_Temp)  Then  Return  False    
If  Not  LocalFileTimeToFileTime(lft_Temp,  lft_LastWriteTime)  Then  Return  False    
 
ll_Handle  =  CreateFileA(astr_PathName,  GENERIC_WRITE,  FILE_SHARE_READ  +  FILE_SHARE_WRITE,  lsa_Temp,  OPEN_EXISTING,  FILE_ATTRIBUTE_ARCHIVE,  lul_NULL)    
If  ll_Handle  <  1

转载于:https://www.cnblogs.com/FollowIT/archive/2006/08/04/467946.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值