Expand|Select|Wrap|Line Numbers
- Imports System
- Imports System.IO.File
- Imports System.IO
- Imports System.Threading
- Imports System.Collections
- Imports System.Collections.Specialized
- Imports System.Diagnostics
- Public Class FileSystemMonitor
- Public Shared Sub Main()
- Dim fsw As New FileSystemWatcher() ' create an object of FileSystemWatcher
- ' set properties of FileSystemWatcher object
- fsw.Path = "c:\Test"
- fsw.IncludeSubdirectories = True
- ' add event handlers
- AddHandler fsw.Created, New FileSystemEventHandler(AddressOf File_Created)
- fsw.EnableRaisingEvents = True ' enable monitoring
- Console.WriteLine("Started Monitoring WinServ Dir. Press enter key to stop.")
- Console.ReadLine()
- End Sub
- ' event handler to handle created event
- Public Shared Sub File_Created(ByVal obj As Object, ByVal e As FileSystemEventArgs)
- Dim fName As String = System.IO.Path.GetFileName(e.FullPath) 'file name with extension
- Dim newPath As String = "C:\Test" 'Newpath with no file
- Dim nPathAndFile As String = String.Concat(newPath, fName) 'Newpath with file and ext
- Dim S As New StringCollection()
- Dim T() As String = {nPathAndFile}
- Dim i As String
- Dim Count As Integer = 0
- For Each i In T
- Count += 1
- Dim di = New DirectoryInfo(newPath)
- Dim fi = di.GetFiles("*", SearchOption.AllDirectories)
- Console.WriteLine(fi.Length.ToString) ' & " " & nPathAndFile)
- Next
- 'If File.Exists(nPathAndFile) Then
- 'Console.WriteLine("Starting Transfer")
- 'Dim psi As New System.Diagnostics.ProcessStartInfo("C:\ftp2.bat")
- 'psi.RedirectStandardOutput = True
- 'psi.WindowStyle = ProcessWindowStyle.Hidden
- 'psi.UseShellExecute = False
- 'Dim ftp As System.Diagnostics.Process
- 'ftp = System.Diagnostics.Process.Start(psi)
- 'Dim myOutput As System.IO.StreamReader = ftp.StandardOutput
- 'Console.WriteLine(myOutput)
- 'ftp.WaitForExit(1000)
- 'If ftp.HasExited Then
- 'Console.WriteLine("Transfer Done")
- 'Dim s As String
- 'For Each s In System.IO.Directory.GetFiles("C:\Test")
- 'System.IO.File.Delete(s)
- 'Next s
- 'End If
- 'For Each i In T
- 'Delete(i)
- 'Thread.Sleep(2000)
- 'Next
- 'End If
- End Sub
- End Class
- 'Dim delt As New System.Diagnostics.ProcessStartInfo("C:\delt.bat")
- 'delt.RedirectStandardOutput = True
- 'delt.WindowStyle = ProcessWindowStyle.Hidden
- 'delt.UseShellExecute = False
- 'Dim delt2 As System.Diagnostics.Process
- 'delt2 = System.Diagnostics.Process.Start(delt)