当有(*.txt或*.doc)文件时。是指有新文件。创建到该文件夹里面

解决方案 »

  1.   

    use Shell Change Notifications:
    http://www.mvps.org/vbnet/index.html?code/shell/shchangenotify.htmor FindChangeNotification:
    http://www.mvps.org/vbnet/index.html?code/shell/shchangenotify.htm
      

  2.   

    这个地方的代码我也找到了,但不能指定监控某种属性(如*.txt)的文件.另外,不能监控文件夹里面的文件夹里面的文件!!!!!!啊!如c:\share\share\1.txt
      

  3.   

    filedatetime函数可以判断文件时间,记住这个时间,监控时判断时间是否改变。
      

  4.   

    module中的代码
    Public Declare Function ShellExecuteEX Lib "shell32.dll" Alias "ShellExecuteEx" (SEI As SHELLEXECUTEINFO) As Long'常量定义
    Public Const SEE_MASK_INVOKEIDLIST = &HC
    Public Const SEE_MASK_NOCLOSEPROCESS = &H40
    Public Const SEE_MASK_FLAG_NO_UI = &H400'定义结构体
    Type SHELLEXECUTEINFO
           cbSize As Long
           fMask As Long
           hWnd As Long
           lpVerb As String
           lpFile As String
           lpParameters As String
           lpDirectory As String
           nShow As Long
           hInstApp As Long
           lpIDList As Long '可以选
           lpClass As String '可以选
           hkeyClass As Long '可以选
           dwHotKey As Long '可以选
           hIcon As Long '可以选
           hProcess As Long '可以选
    End Type'Function 过程
    Public Function ShowProperties(FileName As String, OwnerhWnd As Long) As Long
    Dim SEI As SHELLEXECUTEINFO
    Dim rPro As Long
    '对SEI设置
         With SEI
           .cbSize = Len(SEI)
           .fMask = SEE_MASK_NOCLOSEPROCESS Or SEE_MASK_INVOKEIDLIST Or SEE_MASK_FLAG_NO_UI
           .hWnd = OwnerhWnd
           .lpVerb = "properties"
           .lpFile = FileName
           .lpParameters = vbNullChar
           .lpDirectory = vbNullChar
           .nShow = 0
           .hInstApp = 0
           .lpIDList = 0
    End With
    '调用API
     rPro = ShellExecuteEX(SEI)
    '返回一个成功标志
     ShowProperties = SEI.hInstApp
    End Functionform1中的代码在上面加入CommonDialog控件
    代码如下:
    Private Sub cmdOpen_Click()
    CommonDialog.Filter = "TXT file (*.txt)|*.TXT|Rich Text Format files(*.rtf)|*.RTF|Word file (*.doc)|*.DOC|All file(*.*)|*.*"
    CommonDialog.ShowOpen
    End Sub
    '文件的属性显示
    '调用modset的功能函数 ShowProperties()
    Private Sub cmdPropertiy_Click()
    rPro = ShowProperties(CommonDialog.FileName, Me.hWnd)
    End Sub
      

  5.   

    不是调用WINDOWS的属性,而是要将文件的属性。做为变量。而且监控的问题 还没有解决
      

  6.   

    modual
    'Declaratins:
    Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
    Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As LongPublic Const FILE_ATTRIBUTE_READONLY = &H1
    Public Const FILE_ATTRIBUTE_HIDDEN = &H2
    Public Const FILE_ATTRIBUTE_SYSTEM = &H4
    Public Const FILE_ATTRIBUTE_DIRECTORY = &H10
    Public Const FILE_ATTRIBUTE_ARCHIVE = &H20
    Public Const FILE_ATTRIBUTE_NORMAL = &H80
    Public Const FILE_ATTRIBUTE_TEMPORARY = &H100
    Public Const FILE_ATTRIBUTE_COMPRESSED = &H800Type FILETIME
       LowDateTime          As Long
       HighDateTime         As Long
    End Type
    Type WIN32_FIND_DATA
       dwFileAttributes     As Long
       ftCreationTime       As FILETIME
       ftLastAccessTime     As FILETIME
       ftLastWriteTime      As FILETIME
       nFileSizeHigh        As Long
       nFileSizeLow         As Long
       dwReserved0          As Long
       dwReserved1          As Long
       cFileName            As String * 260  'MUST be set to 260
       cAlternate           As String * 14
    End TypeDeclare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As LongType 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
    Public Function Findfile(xstrfilename) As WIN32_FIND_DATA
    Dim Win32Data As WIN32_FIND_DATA
    Dim plngFirstFileHwnd As Long
    Dim plngRtn As LongplngFirstFileHwnd = FindFirstFile(xstrfilename, Win32Data)  ' Get information of file using API call
    If plngFirstFileHwnd = 0 Then
      Findfile.cFileName = "Error"                              ' If file was not found, return error as name
    Else
      Findfile = Win32Data                                      ' Else return results
    End If
    plngRtn = FindClose(plngFirstFileHwnd)                      ' It is important that you close the handle for FindFirstFile
    End Function
    form
    Public Sub updatestats()
    Dim ftime As SYSTEMTIME               ' Initialise variables
    Dim tfilename As String
    tfilename = dialog.FileName
    Dim filedata As WIN32_FIND_DATAfiledata = Findfile(tfilename)        ' Get informationtxtname = tfilename                   ' Put name in text boxIf filedata.nFileSizeHigh = 0 Then    ' Put size into text box
      txtsize = filedata.nFileSizeLow & " Bytes"
    Else
      txtsize = filedata.nFileSizeHigh & "Bytes"
    End IfCall FileTimeToSystemTime(filedata.ftCreationTime, ftime)   ' Determine Creation date and time, then format it
    lbldate(0) = ftime.wDay & "/" & ftime.wMonth & "/" & ftime.wYear & " " & ftime.wHour & ":" & ftime.wMinute & ":" & ftime.wSecond
    Call FileTimeToSystemTime(filedata.ftLastWriteTime, ftime)  ' Determine Last Modified date and time
    lbldate(1) = ftime.wDay & "/" & ftime.wMonth & "/" & ftime.wYear & " " & ftime.wHour & ":" & ftime.wMinute & ":" & ftime.wSecond
    Call FileTimeToSystemTime(filedata.ftLastAccessTime, ftime) ' Determine Last accessed date (note no time is recorded)
    lbldate(2) = ftime.wDay & "/" & ftime.wMonth & "/" & ftime.wYearIf (filedata.dwFileAttributes And FILE_ATTRIBUTE_HIDDEN) = FILE_ATTRIBUTE_HIDDEN Then
      attributes(1).Value = 1 ' Determine if file has hidden attribute set
    Else
      attributes(1).Value = 0
    End If
    If (filedata.dwFileAttributes And FILE_ATTRIBUTE_SYSTEM) = FILE_ATTRIBUTE_SYSTEM Then
      attributes(2).Value = 1 ' Determine if file has system attribute set
    Else
      attributes(2).Value = 0
    End If
    If (filedata.dwFileAttributes And FILE_ATTRIBUTE_READONLY) = FILE_ATTRIBUTE_READONLY Then
      attributes(3).Value = 1 ' Determine if file has readonly attribute set
    Else
      attributes(3).Value = 0
    End If
    If (filedata.dwFileAttributes And FILE_ATTRIBUTE_ARCHIVE) = FILE_ATTRIBUTE_ARCHIVE Then
      attributes(4).Value = 1 ' Determine if file has archive attribute set
    Else
      attributes(4).Value = 0
    End If
    If (filedata.dwFileAttributes And FILE_ATTRIBUTE_TEMPORARY) = FILE_ATTRIBUTE_TEMPORARY Then
      attributes(5).Value = 1 ' Determine if file has temporary attribute set
    Else
      attributes(5).Value = 0
    End If
    If (filedata.dwFileAttributes And FILE_ATTRIBUTE_NORMAL) = FILE_ATTRIBUTE_NORMAL Then
      attributes(6).Value = 1 ' Determine if file has normal attribute set
    Else
      attributes(6).Value = 0
    End If
    If (filedata.dwFileAttributes And FILE_ATTRIBUTE_COMPRESSED) = FILE_ATTRIBUTE_COMPRESSED Then
      attributes(7).Value = 1 ' Determine if file has compressed attribute set
    Else
      attributes(7).Value = 0
    End If
    End SubPrivate Sub attributes_GotFocus(Index As Integer)
    ok.SetFocus     ' Make it impossible to change check boxes
    End Sub
    Private Sub Form_Load()
    On Error GoTo errhand
    dialog.ShowOpen ' Show open common dialog box
    updatestats     ' Update infomation on form
    Me.Show         ' Show the form
    ok.SetFocus     ' Set focus to Done button
    Exit Suberrhand:
    If Err.Number = cdlCancel Then
      Call MsgBox("You Pressed Cancel!", vbExclamation)   ' Cancel was pressed in common dialog box
    Else
      Call MsgBox("An error has occured!", vbExclamation) ' An unexpected eror has occured
    End If
    End
    End SubPrivate Sub ok_Click()
    End
    End Sub
      

  7.   

    我在updatestats()定义中了一个
    Dim Attributes(7) As Variant另外在模块中dialog.filename被视为未定义的变量。updatestats()应该写在form的代码中,才好使。
      

  8.   

    这样的程序才执行能通过。但一开始就是这个错误 an error occured