Sample scripts

File Watcher runs the Action command when a file arrives. The Action command can take a number of forms:

Note: the complete path to the command must be specified.

Batch Files

.BAT files are run via the command interpreter CMD.EXE (formerly COMMAND.COM). Specify the full path to the batch file in the Command field, and the parameters in the Parameters field.

Sample .BAT files are included in the FileWatcher install folder.

To...Copy each file to a new location

Command:

<complete path\>copy.bat
Parameters:
%FILE%

Create a batch file called copy.bat, and copy the text below into it:

@echo off
rem Used with FileWatcher's command line and the %FILE% macro
rem copy each file to a new location
copy "%1" "c:\location1"

Note: to retain the original folder structure, use the DOS xcopy command instead of copy in the batch file.

To...Copy one file to multiple locations

Command:

<complete path\>copy_multiple.bat

Parameters:

%FILE%

Create a batch file called copy_multiple.bat, and copy the text below into it:

@echo
off
rem Used with FileWatcher's command line and the %FILE% macro rem copy each file to multiple locations copy "%1" "c:\location1" copy "%1" "c:\location2" copy "%1" "c:\location3" copy "%1" "c:\location4"

To...Show the name of the file being processed

Command:

<complete path\>echo.bat

Parameters:

%FILE%

Create a batch file called echo.bat, and copy the text below into it:

@echo off

echo File %1 has arrived and is ready for processing
pause

To...Log the file being processed

Command:

<complete path\>log.bat

Parameters:

%FILE%

Create a batch file called log.bat, and copy the text below into it:

@echo off
date /t >> "c:\logfile.log"
time /t >> "c:\logfile.log"
echo %1 >> "c:\logfile.log"

To...Show a list of files being processed as one group � all on the one command line

Command:

<complete path\>echoparams.bat

Parameters:

%FILE%

Create a batch file called echoparams.bat, and copy the text below into it:

@echo off
echo Command line parameters
echo Used with FileWatcher's command line and the %FILE% macro
echo %%1 %1
echo %%2 %2
echo %%3 %3
echo %%4 %4
echo %%5 %5
echo %%6 %6
echo %%7 %7
echo %%8 %8
echo %%9 %9
pause

To...Show a list of files being processed as one group

Command:

<complete path\>echolist.bat

Parameters:

%FILE%

Create a batch file called echolist.bat, and copy the text below into it:

@echo off
echo List file is %1
echo Used with FileWatcher's command line and the %FILE% macro

echo --[Contents]------------------------
type "%1"
echo --[End]------------------------
pause

To...Move each file to a new folder

Command:

<complete path\>move.bat

Parameters:

%FILE%

Create a batch file called move.bat, and copy the text below into it:

@echo
off
rem Used with FileWatcher's command line and the %FILE% macro
rem Move an incoming file
move "%1" "c:\location1"

To...Play a sound when a file arrives

Command:

<complete path\>play_sound.bat

Parameters:

%FILE%

Create a batch file called play_sound.bat, and copy the text below into it:

@echo off
start sound.wav

To...Print each file

Command:

<complete path\>print.bat

Parameters:

%FILE%

Create a batch file called print.bat, and copy the text below into it:

@echo off
rem Used with FileWatcher's command line and the %FILE% macro
echo Printing %1
print %1
echo Complete

To...View (display) each file

Command:

<complete path\>view.bat

Parameters:

%FILE%

Create a batch file called view.bat, and copy the text below into it:

@echo off
rem Used with FileWatcher's command line and the %FILE% macro
echo Viewing %1
start %1
echo Complete

To...Send email with file as attachment

Command:

<complete path\>sendmail.bat

Parameters:

%FILE%

You need to download a command line sendmail program � try https://www.downloadpipe.com/business/review-absoluteTools-SendMail-CMD-Single-computer-license-42668ToolsSendMa-1176122.html

Note: free versions of sendmail.exe on the web often have viruses and other malware.

 

Create a batch file called sendmail.bat, and copy the text below into it:

@echo off
rem Used with FileWatcher's command line and the %FILE% macro
rem Send mail with this file as the attachment
rem
rem You need to make sure that sendmail.exe is on your system - test this with
rem   sendmail -subject='Test message' yourname@yourdomain.com

sendmail -subject='File arrived %1' -attach='%1' yourname@yourdomain.com

To...Schedule a job if a file arrives

Command:

<complete path\>schedule.bat

Parameters:

%FILE%

Create a batch file called schedule.bat, and copy the text below into it:

@echo off
rem Used with FileWatcher's command line and the %FILE% macro
rem Schedule a process with the file that arrives
rem The Schedule service must be running to use the AT command.

at 1730 /interactive "echo %1" 

echo Scheduling Complete

DOS Commands

Note that the Windows �start� command is a feature of CMD.EXE. To make use of it, you need to create a batch file that uses �start�.

To...Send an Email

To send an email from File Watcher, you need to use a command-line email program - we recommend FREE blat.net (syntax). We strongly suggest you do NOT search for a free download of sendmail.exe - these are 99% guaranteed to contain a virus.

Command:

<complete path\>blat.exe

Parameters:

-to test@test.com -from filewatcher@your.domain -subject "%FILE% arrived" -body "Please use it"

Or even send the newly-arrived file to you:

Command:

<complete path\>blat.exe

Parameters:

-to test@test.com -from filewatcher@your.domain -subject "%FILE% arrived" -body "Please use it" -attach %FILE%