Click here to Skip to main content
15,849,306 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Hide a listView column Pin
bony_baba10-May-06 2:19
bony_baba10-May-06 2:19 
GeneralRe: Hide a listView column Pin
mounirbraham10-May-06 4:43
mounirbraham10-May-06 4:43 
GeneralRe: Hide a listView column Pin
jcrussell10-May-06 19:45
jcrussell10-May-06 19:45 
QuestionWHERE IS the ListSubItems Icon property ?? Pin
mounirbraham9-May-06 14:52
mounirbraham9-May-06 14:52 
QuestionControlling FileSystemWatcher Pin
Wrongway43219-May-06 11:44
Wrongway43219-May-06 11:44 
AnswerRe: Controlling FileSystemWatcher Pin
DSAlbin21-May-06 8:41
DSAlbin21-May-06 8:41 
GeneralRe: Controlling FileSystemWatcher Pin
Wrongway432123-May-06 13:17
Wrongway432123-May-06 13:17 
GeneralRe: Controlling FileSystemWatcher Pin
DSAlbin23-May-06 14:17
DSAlbin23-May-06 14:17 
Hi Dave (that's my name too Big Grin | :-D )

I found a nice program at this link: "http://abstractvb.com/code.asp?A=1081" by someone named Jayesh Jain where I thought his coding technique was useful.

I agree very much with you that the FSW class is not very well documented, particularly in how various combinations of "OR" statements can be expected to behave when messing around with files.

In Jain's code, he uses a combination of "ORing" the .DirectoryName, .Filename, and finally the .Attributes enumerators to define his .NotifyFilter property, e.g.:

mw.NotifyFilter = NotifyFilters.DirectoryName
mw.NotifyFilter = mw.NotifyFilter Or NotifyFilters.FileName
mw.NotifyFilter = mw.NotifyFilter Or NotifyFilters.Attributes

(where mw is an instance of FileSystemWatcher)

he then defines the following handlers:

AddHandler mw.Changed, AddressOf logchange
AddHandler mw.Created, AddressOf logchange
AddHandler mw.Deleted, AddressOf logchange
AddHandler mw.Renamed, AddressOf logrename

and then the following routines (the .Renamed event passes a different signature and thus needs it's own subroutine):

Private Sub logchange(ByVal source As Object, ByVal e As _
System.IO.FileSystemEventArgs)
If e.ChangeType = IO.WatcherChangeTypes.Changed Then
txt_folderactivity.Text &= "File " & e.Name & _
" has been changed" & vbCrLf
End If
If e.ChangeType = IO.WatcherChangeTypes.Created Then
txt_folderactivity.Text &= "File " & e.Name & _
" has been created" & vbCrLf
End If
If e.ChangeType = IO.WatcherChangeTypes.Deleted Then
txt_folderactivity.Text &= "File " & e.Name & _
" has been deleted" & vbCrLf
End If
End Sub

Public Sub logrename(ByVal source As Object, ByVal e As System.IO.RenamedEventArgs)
txt_folderactivity.Text &= "File" & e.OldName & " has been renamed to " & e.Name & vbCrLf
End Sub

I played with this a little, and came up with this logic table:

1) Files streamed into a folder will trigger both the .changed and .created events
2) Files streamed over an already existing files will trigger (2) .changed events
3) Files that are deleted will trigger only the .deleted event
4) Files that have their names changed will trigger both the .renamed and .changed events
5) Files that are dragged/droped into the folder will trigger both a .created and .changed event
6) Files that are created within the folder by right-clicking-->Add new, will trigger only the .created event
7) Files that exist within the directory and are dragged out of it will trigger a .deleted event
8) Opening, editing, and saving changes to a file will trigger (2) .changed events

As you can see, many of these actions will only trigger the .changed event once (1, 4, and 5),...so if place your "log to file" code in the "e.ChangeType = IO.WatcherChangeTypes.Changed" If-then statement above, you should only get (1) entry.

Anyway, that's how I use this class,..just play with it until the actions you expect only cause a single .change event to trigger,..

oh well,...not as "clean" an approach as i'd prefer,.but hopefully it'll work for you!!

-Dave

Dave
GeneralRe: Controlling FileSystemWatcher Pin
Wrongway432124-May-06 11:55
Wrongway432124-May-06 11:55 
GeneralRe: Controlling FileSystemWatcher Pin
DSAlbin24-May-06 13:22
DSAlbin24-May-06 13:22 
QuestionDataGrid Control Pin
Quecumber2569-May-06 11:27
Quecumber2569-May-06 11:27 
Questionhandler problem Pin
meconomou9-May-06 9:18
meconomou9-May-06 9:18 
Questioncombo box Data source Nothing Problem Pin
Hkothari779-May-06 9:02
Hkothari779-May-06 9:02 
AnswerRe: Data source Still Nothing Problem Pin
Hkothari779-May-06 9:04
Hkothari779-May-06 9:04 
QuestionHow to cut part of the piture in a picture box Pin
Murtuza Husain Miyan Patel9-May-06 8:58
professionalMurtuza Husain Miyan Patel9-May-06 8:58 
AnswerRe: How to cut part of the piture in a picture box Pin
Christian Graus9-May-06 11:39
protectorChristian Graus9-May-06 11:39 
QuestionAdding nodes to a treeview control Pin
Raistlin21_459-May-06 8:25
Raistlin21_459-May-06 8:25 
AnswerRe: Adding nodes to a treeview control Pin
digicd19-May-06 17:22
digicd19-May-06 17:22 
GeneralRe: Adding nodes to a treeview control Pin
Raistlin21_4510-May-06 7:01
Raistlin21_4510-May-06 7:01 
AnswerRe: Adding nodes to a treeview control Pin
Hacknight949-May-06 21:37
Hacknight949-May-06 21:37 
GeneralRe: Adding nodes to a treeview control Pin
Raistlin21_4510-May-06 7:05
Raistlin21_4510-May-06 7:05 
GeneralRe: Adding nodes to a treeview control Pin
Hacknight9410-May-06 15:15
Hacknight9410-May-06 15:15 
GeneralRe: Adding nodes to a treeview control Pin
Hacknight9410-May-06 15:21
Hacknight9410-May-06 15:21 
Questionfrom ADO to ADO.NET 2.0 Pin
Gulfraz Khan9-May-06 7:11
Gulfraz Khan9-May-06 7:11 
QuestionHandling Complex Numbers Pin
crtwrght_mrk9-May-06 7:09
crtwrght_mrk9-May-06 7:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.