读书人

怎么用VB修改一个文件夹的创建时间啊注

发布时间: 2012-03-09 16:54:57 作者: rapoo

如何用VB修改一个文件夹的创建时间啊,注意是文件夹,不是文件
上次发帖我自己没说清楚,帖子沉了,现在再发一次,希望大哥们帮忙
我想用VB做一个可以设置文件夹时间的小工具,用来修改PSP上的排列
显示的顺序。
我是想这样做的,点一下按钮,就将文件夹的创建时间修改TEXT里设置的时间,我在网上找到的
那些代码都是只能将文件夹改成与系统当前一样的时间,不能自己设置。大家有更好的代码么?共享一下
或者发到我的邮箱:yyh_qq@163.com

[解决办法]
看看
http://vbnet.mvps.org/index.html?code/fileapi/folderdatetime.htm
[解决办法]

VB code
'form1 codeOption ExplicitPrivate 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 LongPrivate Declare Function SystemTimeToFileTime Lib "kernel32" _        (lpSystemTime As SYSTEMTIME, lpFileTime As FILETIME) As LongPrivate Declare Function SetFileTime Lib "kernel32" (ByVal hFile As Long, _        lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, _        lpLastWriteTime As FILETIME) As LongPrivate Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As LongPrivate Type FILETIME        dwLowDateTime As Long        dwHighDateTime As LongEnd TypePrivate Type SECURITY_ATTRIBUTES        nLength As Long        lpSecurityDescriptor As Long        bInheritHandle As LongEnd TypePrivate 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 IntegerEnd TypePrivate Const GENERIC_READ = &H80000000Private Const GENERIC_WRITE = &H40000000Private Const FILE_SHARE_READ = &H1Private Const FILE_SHARE_WRITE = &H2Private Const OPEN_EXISTING = 3Private Const FILE_FLAG_BACKUP_SEMANTICS = &H2000000Private Const INVALID_HANDLE_VALUE = -1Private 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 = retvalEnd FunctionPrivate Sub Form_Load()    Text1.Text = "2005-09-30 11:11:11"End SubPrivate 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, NewLastWriteTimeEnd Sub 

读书人网 >VB

热点推荐