VerySource

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 775|回复: 2

请教,怎样修改文件的属性

[复制链接]

1

主题

1

帖子

2.00

积分

新手上路

Rank: 1

积分
2.00
发表于 2020-1-22 15:20:01 | 显示全部楼层 |阅读模式
如题,例如要修改某个文件的最后修改时间,创建时间等.谢谢
回复

使用道具 举报

0

主题

100

帖子

53.00

积分

新手上路

Rank: 1

积分
53.00
发表于 2020-2-1 22:09:02 | 显示全部楼层
//文件名:uo_file_function.sru直接导入即可
//也是以前别人给的
$PBExportHeader$uo_file_function.sru
$PBExportComments$获取文件的创建、修改、访问时间。
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
回复

使用道具 举报

0

主题

100

帖子

53.00

积分

新手上路

Rank: 1

积分
53.00
发表于 2020-2-1 22:27:01 | 显示全部楼层

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

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

快速回复 返回顶部 返回列表