Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. FileSystemWatcher

FileSystemWatcher

Scheduled Pinned Locked Moved Visual Basic
question
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zulfikar Ali
    wrote on last edited by
    #1

    I am trying to watch for "n" number of folders. Do I have to create "n" number of FileSystemWatcher instance to do this? If anybody worked on this please advice. Thanks a lot. :rolleyes: Zulfikar Ali

    J 1 Reply Last reply
    0
    • Z Zulfikar Ali

      I am trying to watch for "n" number of folders. Do I have to create "n" number of FileSystemWatcher instance to do this? If anybody worked on this please advice. Thanks a lot. :rolleyes: Zulfikar Ali

      J Offline
      J Offline
      Josep Balague
      wrote on last edited by
      #2

      Is more easy create one folder and five subfolders. You only watch for the parent folder or root folder and FilSystemWatcher, with "true" in watch subdirectories option, watch the six folders. Victor

      Z 1 Reply Last reply
      0
      • J Josep Balague

        Is more easy create one folder and five subfolders. You only watch for the parent folder or root folder and FilSystemWatcher, with "true" in watch subdirectories option, watch the six folders. Victor

        Z Offline
        Z Offline
        Zulfikar Ali
        wrote on last edited by
        #3

        Thanks for your reply. But folders can't be sub folder in my project. Anyway i have figured out the solution. Here is the code if anybody is interested. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim i As Integer Dim strName As String Dim strDBReject As String Dim strParseReject As String 'Load the profile info from the setup XML file Dim dsGetIni As New DataSet() dsGetIni.ReadXml(Application.StartupPath & "\setup.xml") Dim dtGetIni As DataTable = dsGetIni.Tables("Profile") i = dtGetIni.Rows.Count Dim objRow As DataRow() For i = 0 To dsGetIni.Tables("Profile").Rows.Count - 1 strName = dtGetIni.Rows(i)("Name") strDBReject = dtGetIni.Rows(i)("DBReject") watcher(strDBReject) strParseReject = dtGetIni.Rows(i)("ParseReject") watcher(strParseReject) Next End Sub Public Function watcher(ByVal strFolder As String) Dim objWatcher As New System.IO.FileSystemWatcher() 'Folder to watch objWatcher.Path = strFolder 'File extension to watch objWatcher.Filter = "*.pdf" 'Create delegates to handle the events for the FileSystemWatcher AddHandler objWatcher.Created, AddressOf OnFileCreated 'Exclude subdirectories from watching objWatcher.IncludeSubdirectories = True 'Start watching folder objWatcher.EnableRaisingEvents = True End Function Public Sub OnFileCreated(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs) Try 'create new instance of importer Dim FileInfo As New FileInformation(e.FullPath) ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf ProcessFile), FileInfo) Catch ex As Exception End Try End Sub Private Function GetExclusiveAccess(ByVal FilePath As String) As Boolean Try Dim theFile As File Dim strm As Stream = theFile.Open(FilePath, FileMode.Open) 'if we succeed, we can let it go strm.Close() GetExclusiveAccess = True Catch e As Exception GetExclusiveAccess = False End Try End Function Public Sub ProcessFile(ByVal fileInfo As Object) If Thread.CurrentThread.Name = "" Then Thread.CurrentThread.Name = Thread.CurrentThread.GetHa

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups