|
// File name: uo_file_function.sru can be imported directly
// also given by others before
$ PBExportHeader $ uo_file_function.sru
$ PBExportComments $ Gets the file creation, modification, and access time.
forward
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
end forward
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 |
|