vb 怎么更改文件的修改时间
发布网友
发布时间:2022-04-22 23:42
我来回答
共5个回答
热心网友
时间:2023-08-20 16:37
用api函数更改:
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Const GENERIC_WRITE = &H40000000
Private Const OPEN_EXISTING = 3
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function SetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
Private Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As SYSTEMTIME, lpFileTime As FILETIME) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function LocalFileTimeToFileTime Lib "kernel32" (lpLocalFileTime As FILETIME, lpFileTime As FILETIME) As Long
Private Sub SetModiTime(ByVal m_Path As String, ByVal m_Date As Date)
Dim lngHandle As Long
Dim udtFileTime As FILETIME
Dim udtLocalTime As FILETIME
Dim udtSystemTime As SYSTEMTIME
udtSystemTime.wYear = Year(m_Date)
udtSystemTime.wMonth = Month(m_Date)
udtSystemTime.wDay = Day(m_Date)
udtSystemTime.wDayOfWeek = Weekday(m_Date) - 1
udtSystemTime.wHour = Hour(m_Date)
udtSystemTime.wMinute = Minute(m_Date)
udtSystemTime.wSecond = Second(m_Date)
udtSystemTime.wMilliseconds = 0
' convert system time to local time
SystemTimeToFileTime udtSystemTime, udtLocalTime
' convert local time to GMT
LocalFileTimeToFileTime udtLocalTime, udtFileTime
' open the file to get the filehandle
lngHandle = CreateFile(m_Path, GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0)
' change date/time property of the file
SetFileTime lngHandle, udtFileTime, udtFileTime, udtFileTime
' close the handle
CloseHandle lngHandle
MsgBox "The date of the file has been changed to " + Str$(m_Date), vbInformation + vbOKOnly, App.Title
End Sub
热心网友
时间:2023-08-20 16:38
方法:
热心网友
时间:2023-08-20 16:38
给你个思路
第一,在修改文件前把系统时间给改了````呵呵是不是一下子恍然大悟啊,时间改成你之前文件的修改时间
第二,修改之后再把时间调回,因为你用VB,所以基本不用加上时差。直接在程序里换成修改之前的那个时间就OK了
或者,你记下原文件修改的时间,然用VB调系统时间,调成你记下的时间,再修改文件,再调回时间。呵呵。
热心网友
时间:2023-08-20 16:39
用api函数更改:
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Const GENERIC_WRITE = &H40000000
Private Const OPEN_EXISTING = 3
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function SetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
Private Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As SYSTEMTIME, lpFileTime As FILETIME) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function LocalFileTimeToFileTime Lib "kernel32" (lpLocalFileTime As FILETIME, lpFileTime As FILETIME) As Long
Private Sub SetModiTime(ByVal m_Path As String, ByVal m_Date As Date)
Dim lngHandle As Long
Dim udtFileTime As FILETIME
Dim udtLocalTime As FILETIME
Dim udtSystemTime As SYSTEMTIME
udtSystemTime.wYear = Year(m_Date)
udtSystemTime.wMonth = Month(m_Date)
udtSystemTime.wDay = Day(m_Date)
udtSystemTime.wDayOfWeek = Weekday(m_Date) - 1
udtSystemTime.wHour = Hour(m_Date)
udtSystemTime.wMinute = Minute(m_Date)
udtSystemTime.wSecond = Second(m_Date)
udtSystemTime.wMilliseconds = 0
' convert system time to local time
SystemTimeToFileTime udtSystemTime, udtLocalTime
' convert local time to GMT
LocalFileTimeToFileTime udtLocalTime, udtFileTime
' open the file to get the filehandle
lngHandle = CreateFile(m_Path, GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0)
' change date/time property of the file
SetFileTime lngHandle, udtFileTime, udtFileTime, udtFileTime
' close the handle
CloseHandle lngHandle
MsgBox "The date of the file has been changed to " + Str$(m_Date), vbInformation + vbOKOnly, App.Title
End Sub
热心网友
时间:2023-08-20 16:40
vb修改系统时间可是再简单不过了
一个代码就可以实现了
date
=
datevalue("你要修改的日期")
注意这个输入的日期是有格式的
比如说你想修改到8888年8月8日
就是date
=
datevalue("8888-8-8")
千万不能写date
=
datevalue("8888年8月8日")
vb 怎么更改文件的修改时间
用api函数更改:Private Type FILETIME dwLowDateTime As Long dwHighDateTime As LongEnd Type Private Type SYSTEMTIME wYear As Integer wMonth As Integer wDayOfWeek As Integer wDay As Integer wHour As Integer wMinute As Integer wSecond...
VB修改文件时间、年月日时分秒
文件的修改时间用system.io.file.setlastwritetime 如果label1是用打开对话框选择的要加cdlg 核心代码给你了 自己研究吧
VB2005如何修改一个文件的“修改时间”?
使用My.Computer.FileSystem.GetFileInfo可以读取/修改一个指定文件的创建/最后访问/最后修改时间。需要注意的是在学修改一个文件的属性的时候需确保这个文件不是只读的,当然只读属性可以编程去掉。Dim f As IO.FileInfo = My.Computer.FileSystem.GetFileInfo("C:\boot.ini")Dim isReadOnly As BooleanisReadOnly...
VBA中怎么读取文件的属性,如修改时间,类型,大小之类的
返回一个 Variant (Date),此为一个文件被创建或最后修改后的日期和时间。语法 FileDateTime(pathname)必要的 pathname 参数是用来指定一个文件名的字符串表达式。pathname 可以包含目录或文件夹、以及驱动器。FileLen 返回文件长度 返回一个 Long,代表一个文件的长度,单位是字节。语法 FileLen(pathname)必...
VB中如何通过在文本框中输入时间日期然后直接赋值给系统时间日期,从而...
如果正确,则使用Date语句和Time语句设置系统的日期和时间。代码如下:Private Sub Command1_Click()If IsDate(Text1.Text) Then '设置系统日期和时间 Date = Format(CDate(Text1), "yyyy-mm-dd")Time = Format(CDate(Text1), "hh:mm:ss")Else MsgBox "输入时间错误!"End If End Sub 一般...
VB程序如何读取自己的版本号和时间信息
'版本号可以用app方式查看 Private Sub Form_Load()Label1.Caption = App.Revision End Sub '时间可以参考一下 如果只是查看大小、修改时间的话,可以直接使用VB内建函数:返回文件修改时间:FileDateTime(文件路径)返回文件字节大小:FileLen(文件路径)示例:Private Sub Form_Load()Dim sOut As String ...
如何使用vb查看文件创建时间、修改时间、访问时间等信息
Dim ObjFile As File Set ObjFile = ObjFileSystem.GetFile("d:/19.txt")'文件名 Debug.Print ObjFile.DateCreated '文件创建时间 Debug.Print ObjFile.DateLastAccessed '文件访问时间 Debug.Print ObjFile.DateLastModified '文件修改时间 FileSizes = ObjFile.Size ‘文件大小 字节为单位 ...
VB 如何读取并修改数码照片的拍摄时间
也就是对应你那个代码的完整代码发送给你了。你在这个没有问题的代码上再研究并剔出你需要的那部分代码就可以了,这样就简单多啦。如下图就是用完整的没有问题的代码读出你那张照片的所有Exif信息的实例啦。希望你这个目的达到后并将你完成的代码发一份到邮箱yangyingjun666@163.com我再看看哈。
VB 检测网络一个文件的修改时间
MsgBox "文件最后更新时间:" & GMT_Trans(XMLHTTP.getResponseHeader("Last-Modified"))End If End Sub Function GMT_Trans(s_time)str_time = Mid(s_time, InStr(1, s_time, ",") + 1, InStr(1, s_time, "GMT") - InStr(1, s_time, ",") - 1)str_time = Trim(str_time)...
求VB中SetFileTime函数修改文件创建时间例句
' createfile在这里不是创建,是打开要修改的文件C:\abc.xls lngHandle = CreateFile("C:\abc.xls", GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0)' 改变文件时间并msgbox结果 MsgBox SetFileTime(lngHandle, udtFileTime, udtFileTime, udtFileTime)...