Solved application Hot folder

Posted on 2010-01-07
Last Modified: 2012-05-08
So the question is how can I get a app to watch a folder and then run commands on a file once it's completed transferring into that folder?
Question by:cpservice
    LVL 4

    Expert Comment

    LVL 4

    Expert Comment


    Author Comment

    This project is in C## as is all the help. Any idea how this goes in
    LVL 69

    Accepted Solution

    LVL 4

    Expert Comment

    You have juste to drop a FileSystemWatcher in your form and in the code your trap event you want....

    can't be more simple.....
    example for changed (FileSystemWatcher1= id of my object dropped)
    Private Sub FileSystemWatcher1_Changed(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles FileSystemWatcher1.Changed

        End Sub


    Author Comment

    This is what I have but it seems not to work.... I get no errors in code though...
    Imports System.IO
    Public Class Form1
        Inherits System.Windows.Forms.Form
        Public Function ExecCommand(ByRef CommandLine As String, _
                                Optional ByRef Arguments As String = "", _
                                Optional ByRef Waitforexit As Boolean = True) As Integer
            Dim psi As New ProcessStartInfo()
            Dim p As Process
            With psi
                .FileName = CommandLine
                .Arguments = Arguments
                .WindowStyle = ProcessWindowStyle.Hidden 'This avoid a text window being opened
            End With
                p = Process.Start(psi) 'This line runs the command
                If Waitforexit Then p.WaitForExit() 'This wait until the command ends
                Return p.ExitCode
            Catch e As System.Exception
                'Catch errors here
            End Try
        End Function
    #Region " Windows Form Designer generated code "
        Public Sub New()
            'This call is required by the Windows Form Designer.
            'Add any initialization after the InitializeComponent() call
        End Sub
        'Form overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                End If
            End If
        End Sub
        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer
        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        Friend WithEvents lstFiles As System.Windows.Forms.ListBox
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Me.lstFiles = New System.Windows.Forms.ListBox
            Me.lstFiles.Dock = System.Windows.Forms.DockStyle.Fill
            Me.lstFiles.Location = New System.Drawing.Point(0, 0)
            Me.lstFiles.Name = "lstFiles"
            Me.lstFiles.Size = New System.Drawing.Size(1025, 368)
            Me.lstFiles.TabIndex = 0
            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
            Me.ClientSize = New System.Drawing.Size(1025, 372)
            Me.Name = "Form1"
            Me.Text = "Form1"
        End Sub
    #End Region
        Private m_WatchDirectory As String
        Private WithEvents m_FileSystemWatcher As FileSystemWatcher
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            lstFiles.Items.Add(Now.ToString() & " Starting")
            ' Get the path to the directory we will watch.
            'm_WatchDirectory = Application.StartupPath
            'm_WatchDirectory = m_WatchDirectory.Substring(0, m_WatchDirectory.LastIndexOf("\"))
            m_WatchDirectory &= "c:\docume~1\username\desktop\howtofolderwatcher\baton\bad"
            ' Make the FileSystemWatcher.
            m_FileSystemWatcher = New FileSystemWatcher(m_WatchDirectory, "*.mpg")
            m_FileSystemWatcher.NotifyFilter = 0
            m_FileSystemWatcher.NotifyFilter = m_FileSystemWatcher.NotifyFilter Or NotifyFilters.FileName
            m_FileSystemWatcher.EnableRaisingEvents = True
            ' Process any files that already exist.
        End Sub
        ' Process a new file.
        Private Sub m_FileSystemWatcher_Created(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles m_FileSystemWatcher.Created
        End Sub
        ' Process existing files.
        Private Sub ProcessExistingFiles(ByVal directory_name As String)
            Dim dir_info As New DirectoryInfo(directory_name)
            Dim file_infos As FileInfo() = dir_info.GetFiles()
            For Each fi As FileInfo In file_infos
            Next fi
        End Sub
        ' Process a file.
        Private Sub ProcessFile(ByVal file_name As String)
            lstFiles.Items.Add(Now.ToString() & " Processed " & file_name)
            'ExecCommand("cmd", " /c " & "c:\docume~1\username\desktop\howtofolderwatcher\baton\bad\dtrmxutil.exe " & file_name & " " & file_name & ".mpg" & " 6000000", Waitforexit:=True)
        End Sub
    End Class

    Open in new window

    LVL 69

    Expert Comment

    by:Éric Moreau
    can you try a simpler forlder like c:\test

    Author Closing Comment

    Thank you!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
    The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now