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

解决方案 »

  1.   

    用API啊...SetFileTime VB声明 
    Declare Function SetFileTime Lib "kernel32" Alias "SetFileTime" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long 
    说明 
    设置文件的创建、访问及上次修改时间 
    返回值 
    Long,非零表示成功,零表示失败。会设置GetLastError 
    参数表 
    参数 类型及说明 
    hFile Long,系统文件句柄 
    lpCreationTime FILETIME,文件的创建时间 
    lpLastAccessTime FILETIME,文件上一次访问的时间 
    lpLastWriteTime FILETIME,文件最近一次修改的时间 
      

  2.   

    看看
    http://vbnet.mvps.org/index.html?code/fileapi/folderdatetime.htm
      

  3.   


    'form1 code
    Option 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 Long
    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As LongPrivate Type FILETIME
            dwLowDateTime As Long
            dwHighDateTime As Long
    End TypePrivate Type SECURITY_ATTRIBUTES
            nLength As Long
            lpSecurityDescriptor As Long
            bInheritHandle As Long
    End 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 Integer
    End TypePrivate 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 = -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 = retval
    End FunctionPrivate 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, NewLastWriteTimeEnd Sub
      

  4.   

    没沉啊,我们都给你答案了,楼主,唉
    http://topic.csdn.net/u/20100414/17/e18696f6-14d5-4079-a7ab-c6f0741c4361.html