Home Image-Pro Automation (Macros, Apps, Reports)

How to automatically process image files copied to a Windows folder

The following 2 macros allow monitoring a specified folder and automatically load any TIFF file copied to it for processing. Run the StartMonitoring macro to activate the process.

Imports System.IO

Public Module Macros

    ' The Windows object used to monitor the file system '
    Private WithEvents _fileSystemWatcher As System.IO.FileSystemWatcher

    ' The path of a folder to monitor '
    Private Const cIncomingFolder As String = "D:\Incoming"

    ' Run this macro to start monitoring cIncomingFolder '
    Sub StartMonitoring
        _fileSystemWatcher = New FileSystemWatcher
        _fileSystemWatcher.Path = cIncomingFolder
        _fileSystemWatcher.Filter = "*.tif"
        _fileSystemWatcher.SynchronizingObject = ThisApplication.MainForm
        _fileSystemWatcher.EnableRaisingEvents=True
    End Sub

    Private Sub _fileSystemWatcher_Created(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles _fileSystemWatcher.Created

        ' Wait for the file to be copied '
        While True
            Try
                Dim fs As New FileStream(e.FullPath,FileMode.Open,FileAccess.ReadWrite)
                fs.Close
                Exit While
            Catch ex As System.Exception
            End Try
        End While

        ' Load the file in the application for processing '
        Dim docList1
        With Application.DocumentCommands.Open(Nothing)
            .Filenames = New String() {e.FullPath}
            .Run(docList1)
        End With

    End Sub

End Module
Sign In or Register to comment.