Monitor Folder For New Downloads And Trigger Bat File UPDATED

Monitor Folder For New Downloads And Trigger Bat File

Automobile-Renaming PDF Documents using a Hot-Folder

Introduction
It is often convenient to a monitor a specific binder (called a "hot-folder") and automatically rename every new file placed into it. This mode there is no need to manually run any batch file or awarding, the files are getting renamed dynamically, equally they are beingness placed into the "hot-binder".
Using a hot-folder to rename PDF files
This tutorial is going to focus entirely on how to monitor a folder and process the files. Delight see a previous tutorial on details how to configure AutoSplit to automobile-rename files and how to create a command-line BAT file..
Prerequisites
Yous need a re-create of Adobe® Acrobat® along with the AutoSplit plug-in installed on your figurer in order to employ this tutorial. Both are available equally trial versions.
Overview
In this tutorial we volition apply the following files:
  • RenamingSettings.docren - Auto-Split auto-renaming settings.
  • HotFolder.BAT - a batch file that starts Adobe Acrobat and applies RenamingSettings.docren to the input file.
  • WatchFolder.ps1 - a Powershell script that monitors a folder and runs HotFolder.BAT on each new file.
Please see the previous tutorial on how to create RenamingSettings.docren and HotFolder.BAT files.
BAT File Syntax
We would need to make a single alter to the BAT file created in the previous tutorial and make sure it tin can have a filename as a parameter that is passed to the BAT file. This fashion the folder-monitoring script or awarding can laissez passer a filename that needs to be processed. Use Gear up AUTOSPLIT_INPUT_FILE=%1 to specify the input filename. Annotation that %i refers to a offset command-line parameter that is passed to the BAT file during the excution.
Here is the HotFolder.BAT file nosotros are going to apply. It starts Adobe Acrobat and runs an auto-renaming operation on a PDF file that is passed to it equally a parameter:

SET AUTOSPLIT_INPUT_FOLDER=%ane
SET AUTOSPLIT_CONFIG_FILE=C:\Data\RenamingSettings.docren
SET AUTOSPLIT_BAT_ENABLE=ON
SET AUTOSPLIT_MODE=RenameFile
Fix AUTOSPLIT_LOG_FILE=C:\Data\HotFolder\AutoSplitLog.txt
"C:\Plan Files (x86)\Adobe\Acrobat DC\Acrobat\Acrobat.exe" /n /h

Monitoring a Folder using a Powershell Script
There are many different means to monitor a binder. We are going to show how to apply a Powershell script to practise that. PowerShell is a job automation and configuration management framework from Microsoft, consisting of a command-line trounce and associated scripting language. The script beneath is an adaptation of the method explained in the following excelent online article. Refer to this page for in-depth details and discussions on the Powershell programming methods.
Here is the Powershell script that monitors the c:\Data\HotFolder folder and runs HotFolder.BAT file on every file that is copied into it. Re-create the post-obit code into a text file and salve information technology with *.ps1 file extension (for example: WatchFolder.ps1). If you want to monitor a dissimilar folder or specify a dissimilar BAT file, and so make changes accordingly.
Important: The following script is provided "as-is" without warranty of any kind. Use it at your own adventure.
### This script monitors a hot-folder and starts a BAT file on every new file placed into information technology ### Replace the post-obit variables with your own values ### $Path - full file path to the hot-folder ### $logPath = "C:\Data\HotFolder\LogFile.txt" - path to the log file ### c:\information\HotFolder.BAT - full file path to the BAT file to execute  try { ### Prepare FOLDER TO WATCH      $Path = "C:\Data\HotFolder"  ### SET FILE TYPES TO Picket + SUBFOLDERS Yeah/NO     $watcher = New-Object System.IO.FileSystemWatcher     $watcher.Path = $Path     $watcher.Filter = "*.pdf"     $watcher.IncludeSubdirectories = $false    ### RUN BAT FILE AND Pass FILENAME PARAMETER          $action = { $path = $Consequence.SourceEventArgs.FullPath 		$changeType = $Consequence.SourceEventArgs.ChangeType 		$logline = "$(Go-Date), $changeType, $path"                 ### add a record to a log file    		$logPath = "C:\Data\HotFolder\LogFile.txt"                 Add-Content $logPath -value $logline 		c:\data\HotFolder.BAT $path -Verb runas               }      ### WATCH FOR NEW FILES CREATED IN THE FOLDER   $handlers = . {     	Register-ObjectEvent $watcher "Created" -Action $action 	}     Write-Host "Watching for new files in $Path"     $watcher.EnableRaisingEvents = $true    do   {     # Wait-Event waits for a second and stays responsive to events     # Outset-Sleep in contrast would Non work and ignore incoming events     Await-Effect -Timeout 5      # write a dot to indicate we are still monitoring:     Write-Host "." -NoNewline            } while ($true) } finally { # this gets executed when user presses CTRL+C:      # cease monitoring   $watcher.EnableRaisingEvents = $false      # remove the result handlers   $handlers | ForEach-Object {     Unregister-Event -SourceIdentifier $_.Name   }      # event handlers are technically implemented as a special kind   # of background task, and so remove the jobs now:   $handlers | Remove-Job      # properly dispose the FileSystemWatcher:   $watcher.Dispose()      Write-Warning "End folder monitoring." }              
How to Start and Stop Monitoring
  1. Create and save WatchFolder.ps1 file based on the script example higher up.
  2. Right-click on the WatchFolder.ps1 in Windows Explorer and select "Run with Powershell" from a popup carte du jour.
  3. Powershell window volition appear on screen, monitoring is active at present.
  4. Press Ctrl+C or simply shut Powershell window to stop monitoring.
The script will output a dot every v seconds to point that it is live and working.
Powershell window output
Log Files
The script will also create and maintain a log file (C:\Information\HotFolder\LogFile.txt) that records time when a new file has been placed into a folder. Edit the script if you do not need this functionality.
The HotFolder.BAT file executed by folder-monitoring script volition also create a separate log file that records every file that has been processed. The log file shows the quondam and new file name for every file that have been successfully candy. It will also record any errors encountered during the execution. Note, that some PDF files cannot be renamed due to the security settings or countersign-protection.
Log file records
Yous can observe more AutoSplit tutorials hither.

DOWNLOAD HERE

Posted by: hickstrinnow.blogspot.com

Post a Comment

Previous Post Next Post