VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



this code will check a particular drive or a directory and all the file and subdirectores inside it

by T.SAROJ KUMAR (2 Submissions)
Category: Windows System Services
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 17th February 2004
Date Added: Mon 8th February 2021
Rating: (1 Votes)

this code will check a particular drive or a directory and all the file and subdirectores inside it and the changes made inside it..... it

API Declarations


Inherits System.Windows.Forms.Form
Dim WithEvents watcher As New System.IO.FileSystemWatcher()
Dim b As Byte


Rate this code will check a particular drive or a directory and all the file and subdirectores inside it



        watcher.Path = "d:\saroj"
        watcher.Filter = "*.*"
        MsgBox(System.Environment.StackTrace.ToString())
        watcher.IncludeSubdirectories = True
        watcher.NotifyFilter = IO.NotifyFilters.CreationTime Or IO.NotifyFilters.DirectoryName Or IO.NotifyFilters.FileName Or IO.NotifyFilters.LastAccess Or IO.NotifyFilters.LastWrite Or IO.NotifyFilters.Size
        watcher.EnableRaisingEvents = True
        b = 0
    End Sub

    Private Sub watcher_Changed(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles watcher.Changed
        If b = 0 Then
            writelog(e.Name, e.ChangeType.ToString & "   By : " & System.Environment.UserName)
            b = 1
        End If
    End Sub
    Private Function writelog(ByVal strFile As String, ByVal strChange As String) As Boolean
        Dim sw As System.IO.StreamWriter = New System.IO.StreamWriter("d:\lk.txt", True)
        sw.WriteLine(strFile & "          " & strChange)
        sw.Close()
    End Function

    Private Sub watcher_Created(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles watcher.Created
        writelog(e.Name, e.ChangeType.ToString)
        b = 0
    End Sub

    Private Sub watcher_Deleted(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles watcher.Deleted
        writelog(e.Name, e.ChangeType.ToString)
        b = 0
    End Sub

    Private Sub watcher_Renamed(ByVal sender As Object, ByVal e As System.IO.RenamedEventArgs) Handles watcher.Renamed
        writelog(e.OldName, e.ChangeType.ToString & " to " & e.Name)
        b = 0
    End Sub


Download this snippet    Add to My Saved Code

this code will check a particular drive or a directory and all the file and subdirectores inside it Comments

No comments have been posted about this code will check a particular drive or a directory and all the file and subdirectores inside it. Why not be the first to post a comment about this code will check a particular drive or a directory and all the file and subdirectores inside it.

Post your comment

Subject:
Message:
0/1000 characters