| |

VerySource

 Forgot password?
 Register
Search
View: 780|Reply: 2

Ask, how to modify the attributes of the file

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-22 15:20:01
| Show all posts |Read mode
Such as the title, for example, to modify the last modification time, creation time of a file. Thank you
Reply

Use magic Report

0

Threads

100

Posts

53.00

Credits

Newbie

Rank: 1

Credits
53.00

 Tunisia

Post time: 2020-2-1 22:09:02
| Show all posts
// 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
Reply

Use magic Report

0

Threads

100

Posts

53.00

Credits

Newbie

Rank: 1

Credits
53.00

 Unknown

Post time: 2020-2-1 22:27:01
| Show all posts
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 Then Return False

If Not SetFileTime (ll_Handle, lft_CreationTime, lft_LastAccessTime, lft_LastWriteTime) Then
CloseHandle (ll_Handle)
Return False
End If
CloseHandle (ll_Handle)

Return True

end function

on uo_file_function.create
call super :: create
TriggerEvent (this, "constructor")
end on

on uo_file_function.destroy
TriggerEvent (this, "destructor")
call super :: destroy
end on
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list