在监测文件变化的时候,监测到了新建、删除、修改文件的文件名,但是就是获得不了文件的全路径。
当然,也能得到当前变化文件的handle。
如何获得文件的完全路径?

解决方案 »

  1.   

    Private Const OPEN_EXISTING = 3
    Private Type FILETIME
        dwLowDateTime As Long
        dwHighDateTime As Long
    End Type
    Private Type BY_HANDLE_FILE_INFORMATION
        dwFileAttributes As Long
        ftCreationTime As FILETIME
        ftLastAccessTime As FILETIME
        ftLastWriteTime As FILETIME
        dwVolumeSerialNumber As Long
        nFileSizeHigh As Long
        nFileSizeLow As Long
        nNumberOfLinks As Long
        nFileIndexHigh As Long
        nFileIndexLow As Long
    End Type
    Private Declare Function GetFileInformationByHandle Lib "kernel32" (ByVal hFile As Long, lpFileInformation As BY_HANDLE_FILE_INFORMATION) As Long
    Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    Private Sub Form_Load()
        'KPD-Team 2001
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        Dim hFile As Long, FileInfo As BY_HANDLE_FILE_INFORMATION
        'create a handle to the file 'c:\autoexec.bat'
        hFile = CreateFile("c:\autoexec.bat", 0, 0, ByVal 0&, OPEN_EXISTING, 0, ByVal 0&)
        'retrieve the file information
        GetFileInformationByHandle hFile, FileInfo
        'close the handle
        CloseHandle hFile
        'show the result
        MsgBox "File size: " + CStr(FileInfo.nFileSizeLow), vbInformation
    End Sub
      

  2.   

    看看是不是你要的:http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=196541