我在csdn上下载了一个监控文件夹的程序,修改了一下,不过还有问题。程序是监控c:\aaa文件夹下的文件改变情况。我现在只想将新增到c:\aaa下的文件,列到list1上,原有的文件名不需列出,只对新增加的文件进行操作,不知程序怎么改?谢谢程序如下:'form文件
Option ExplicitDim hChangeHandle As Long
Dim hWatched As Long
Dim terminateFlag As LongPrivate Sub Form_Load()lbmsg = "Press 'Begin Watch'"End Sub
Private Sub cmdEnd_Click()If hWatched > 0 Then Call WatchDelete(hWatched)Unload Me
Set Form1 = NothingEnd Sub
Private Sub cmdStop_Click()
Call WatchDelete(hWatched)
hWatched = 0
cmdbegin.Enabled = True
lbmsg = "Press 'Begin Watch'"
End Sub
Private Sub cmdBegin_Click()Dim r As Long
Dim watchPath As String
Dim watchStatus As LongwatchPath = "c:\aaa"terminateFlag = False
cmdbegin.Enabled = Falselbmsg = "Using Explorer and Notepad, create, modify, rename, delete or "
lbmsg = lbmsg & "change the attributes of a text file in the watched directory."""'WatchChangeAction watchPathMsgBox "Beginning watching of folder " & watchPath & " .. press OK"hWatched = WatchCreate(watchPath, FILE_NOTIFY_FLAGS)watchStatus = WatchDirectory(hWatched, 100)'If watchStatus = 0 Then'WatchChangeAction watchPath'MsgBox "The watched directory has been changed. Resuming watch..."Do
watchStatus = WatchResume(hWatched, 100)If watchStatus = -1 Then
MsgBox "Watching has been terminated for " & watchPathElse: WatchChangeAction watchPath
MsgBox "The watched directory has been changed again."End IfLoop While watchStatus = 0
'Else
'MsgBox "Watching has been terminated for " & watchPath'End IfEnd SubPrivate Function WatchCreate(lpPathName As String, flags As Long) As Long
WatchCreate = FindFirstChangeNotification(lpPathName, False, flags)End Function
Private Sub WatchDelete(hWatched As Long)Dim r As LongterminateFlag = True
DoEventsr = FindCloseChangeNotification(hWatched)End Sub
Private Function WatchDirectory(hWatched As Long, interval As Long) As LongDim r As LongDor = WaitForSingleObject(hWatched, interval)
DoEventsLoop While r <> 0 And terminateFlag = FalseWatchDirectory = rEnd Function
Private Function WatchResume(hWatched As Long, interval) As BooleanDim r As Longr = FindNextChangeNotification(hWatched)Dor = WaitForSingleObject(hWatched, interval)
DoEventsLoop While r <> 0 And terminateFlag = FalseWatchResume = rEnd Function
Private Sub WatchChangeAction(fPath As String)
Dim filenom As String
Dim WholeFile As String
filenom = Dir(fPath & "\" & "*.txt")
  
Do While filenom <> ""
    
   
     WholeFile = fPath & "\" & filenom
    List1.AddItem "path: " & vbTab & filenom
    
    filenom = Dir$Loop
 
End Sub 
'bas文件
Option ExplicitPublic Const INFINITE = &HFFFFPublic Const FILE_NOTIFY_CHANGE_FILE_NAME As Long = &H1
Public Const FILE_NOTIFY_CHANGE_DIR_NAME As Long = &H2
Public Const FILE_NOTIFY_CHANGE_ATTRIBUTES As Long = &H4
Public Const FILE_NOTIFY_CHANGE_SIZE As Long = &H8
Public Const FILE_NOTIFY_CHANGE_LAST_WRITE As Long = &H10
Public Const FILE_NOTIFY_CHANGE_LAST_ACCESS As Long = &H20
Public Const FILE_NOTIFY_CHANGE_CREATION As Long = &H40
Public Const FILE_NOTIFY_CHANGE_SECURITY As Long = &H100
Public Const FILE_NOTIFY_FLAGS = FILE_NOTIFY_CHANGE_ATTRIBUTES Or _
FILE_NOTIFY_CHANGE_FILE_NAME Or _
FILE_NOTIFY_CHANGE_LAST_WRITEDeclare Function FindFirstChangeNotification Lib "kernel32" _
Alias "FindFirstChangeNotificationA" _
(ByVal lpPathName As String, _
ByVal bWatchSubtree As Long, _
ByVal dwNotifyFilter As Long) As LongDeclare Function FindCloseChangeNotification Lib "kernel32" _
(ByVal hChangeHandle As Long) As LongDeclare Function FindNextChangeNotification Lib "kernel32" _
(ByVal hChangeHandle As Long) As LongDeclare Function WaitForSingleObject Lib "kernel32" _
(ByVal hHandle As Long, ByVal dwMilliseconds As Long) As LongPublic Const WAIT_OBJECT_0 = &H0
Public Const WAIT_ABANDONED = &H80
Public Const WAIT_IO_COMPLETION = &HC0
Public Const WAIT_TIMEOUT = &H102
Public Const STATUS_PENDING = &H103
 
''控件列表
'list1是LIST控件
'lbmsg是label控件
'COMMAND控件有cmdbegin,cmdstop,cmdend