怎么用VB修改一个文件夹的创建时间啊注意是文件夹,不是文件
如何用VB修改一个文件夹的创建时间啊,注意是文件夹,不是文件
上次发帖我自己没说清楚,帖子沉了,现在再发一次,希望大哥们帮忙
我想用VB做一个可以设置文件夹时间的小工具,用来修改PSP上的排列
显示的顺序。
我是想这样做的,点一下按钮,就将文件夹的创建时间修改TEXT里设置的时间,我在网上找到的
那些代码都是只能将文件夹改成与系统当前一样的时间,不能自己设置。大家有更好的代码么?共享一下
或者发到我的邮箱:yyh_qq@163.com
------解决方案--------------------
看看
http://vbnet.mvps.org/index.html?code/fileapi/folderdatetime.htm
------解决方案--------------------
上次发帖我自己没说清楚,帖子沉了,现在再发一次,希望大哥们帮忙
我想用VB做一个可以设置文件夹时间的小工具,用来修改PSP上的排列
显示的顺序。
我是想这样做的,点一下按钮,就将文件夹的创建时间修改TEXT里设置的时间,我在网上找到的
那些代码都是只能将文件夹改成与系统当前一样的时间,不能自己设置。大家有更好的代码么?共享一下
或者发到我的邮箱:yyh_qq@163.com
------解决方案--------------------
看看
http://vbnet.mvps.org/index.html?code/fileapi/folderdatetime.htm
------解决方案--------------------
- VB code
'form1 code Option Explicit Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" _ (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, _ ByVal dwShareMode As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, _ ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, _ ByVal hTemplateFile As Long) As Long Private Declare Function SystemTimeToFileTime Lib "kernel32" _ (lpSystemTime As SYSTEMTIME, lpFileTime As FILETIME) 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 CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Type FILETIME dwLowDateTime As Long dwHighDateTime As Long End Type Private Type SECURITY_ATTRIBUTES nLength As Long lpSecurityDescriptor As Long bInheritHandle 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_READ = &H80000000 Private Const GENERIC_WRITE = &H40000000 Private Const FILE_SHARE_READ = &H1 Private Const FILE_SHARE_WRITE = &H2 Private Const OPEN_EXISTING = 3 Private Const FILE_FLAG_BACKUP_SEMANTICS = &H2000000 Private Const INVALID_HANDLE_VALUE = -1 Private Function SetDirTime(DirName As String, NewCreationTime As SYSTEMTIME, _ NewLastAccessTime As SYSTEMTIME, NewLastWriteTime As SYSTEMTIME) As Boolean Dim hDir As Long Dim lpCreationTime As FILETIME Dim lpLastAccessTime As FILETIME Dim lpLastWriteTime As FILETIME Dim retval As Boolean Dim sAttribute As SECURITY_ATTRIBUTES hDir = CreateFile(DirName, GENERIC_WRITE, FILE_SHARE_READ, sAttribute, _ OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0) If hDir = INVALID_HANDLE_VALUE Then SetDirTime = False: Exit Function SystemTimeToFileTime NewCreationTime, lpCreationTime SystemTimeToFileTime NewLastWriteTime, lpLastWriteTime SystemTimeToFileTime NewLastAccessTime, lpLastAccessTime retval = SetFileTime(hDir, lpCreationTime, lpLastAccessTime, lpLastWriteTime) CloseHandle (hDir) SetDirTime = retval End Function Private Sub Form_Load() Text1.Text = "2005-09-30 11:11:11" End Sub Private Sub Command1_Click() Dim NewCreationTime As SYSTEMTIME Dim NewLastAccessTime As SYSTEMTIME '不修改时不用赋值 Dim NewLastWriteTime As SYSTEMTIME '不修改时不用赋值 NewCreationTime.wYear = Year(Text1.Text) NewCreationTime.wMonth = Month(Text1.Text) NewCreationTime.wDay = Day(Text1.Text) NewCreationTime.wDayOfWeek = Weekday(Text1.Text) NewCreationTime.wHour = Hour(Text1.Text) - 8 NewCreationTime.wMinute = Minute(Text1.Text) NewCreationTime.wSecond = Second(Text1.Text) SetDirTime "c:\1", NewCreationTime, NewLastAccessTime, NewLastWriteTime End Sub