About capturing txt files

seth-gr

Member
Joined
May 21, 2007
Messages
8
Location
Greece
Programming Experience
Beginner
Hello i need to build a program in vb that can monitor a folder and if a txt file added in this folder can capture it translate it into another set of commands which i provide through the code and then send it to serial port
Is there anyone that can give me any help or maybe a link to find some information?


Thank you a lot
 
Thank you very much but however i have an error in my code:
Additional information: Object reference not set to an instance of an object.
and visual studio marks yellow this line
watchfile.filter=*.txt"
VB.NET:
Imports System.IO
Imports System.Diagnostics

Public Class Form1
  Public watchfolder As FileSystemWatcher
    Public watchfile As FileSystemWatcher


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


        watchfolder = New System.IO.FileSystemWatcher()

        watchfolder.Path = "c:\800\"
        watchfile.Filter = "*.txt"
        AddHandler watchfolder.Created, AddressOf logchange
        watchfolder.EnableRaisingEvents = True


    End Sub

    Private Sub logchange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs)

        If e.ChangeType = IO.WatcherChangeTypes.Created Then
            watchfile.Filter = "*.txt"
            MsgBox("there is a file ")

        End If

    End Sub

End Class
 
Last edited by a moderator:
I didn't load your code to try, but I think you just need to instantiate watchfile like you do watchfolder. Add
VB.NET:
watchfile = New System.IO.FileSystemWatcher()
no?
 
thank you for your assistance I added this code but the problem remains i dont have the error but i still can't seperate the type of files I have the msgbox appeared in any filetype
 
Back
Top