HOWTO check for new files, process and move...

My problem

I was to find a solution where files copied to a folder automatic was transformed. In this case it was images, pictures. Copied to a special folder, transformed and rotated instant. This auto-chk-tool with scripting features was hard to find...

One solution

This simple tool ChkMagick installs as a service in windows, listens to a folder, and performs one or more actions to the files which are placed in that folder.

It uses the windows FindFirstChangeNotification which means it does use very little resources. (A nonsense benchmark, Idle time 4886h, ChkMagick 6s)

Download and install


ChkMagick.ini file format

chkmagick.ini is read when the service starts.
  1. if there is a chkmagick-computername.ini it is prefered
  2. if above does not exists it checks for chkmagick.ini
  3. if chkmagick.ini does not exists, the service stops

From the [Setup] section you set defaults values for the rest of the sections.
Root=where all commands below resides, when no path is givenRoot=c:\programs\command
Prio=default process priority class, Low|Normal|HighLow=Idle_priority_class
SubT=default subtree flag, 0|10=False
LogL=loglevel, 0..9, when implementing a new function set to nonzero1LogL=2
Time=maximum wait time for the commands below, ms18000=18s
Kill=0|1, terminate process if not finished within time above0=False
Sleep=wait time after notify occurs1000=1s
File=default filename mask in "To" directoryFile=%fnh
MinFileSize=the minimum filesize (bytes) to consider processing, file is moved but not processed-1
MaxFileSize=the maximum filesize to consider processing-1

For every [Event] you need to define you define a new section as follows
Root=root path for the commands in this section[Setup]Root
Prio=default process priority class, Low|Normal|High[Setup]Prio
LogL=loglevel for this section[Setup]LogL
Time=maximum wait time for this section[Setup]Time
Kill=it time is reached and not finished then kill process[Setup]Kill
Sleep=wait time for this section[Setup]Sleep
MinFileSize=minimum filesize, this section[Setup]MinFileSize
MaxFileSize=maximum filesize, this section[Setup]MaxFileSize
From=The folder/directory to listen for change,
when a file is copied/created in this the process begins.
MUST be a valid directory. If directory does not exist nothing will happen (a note in the chkmagick.err file)
SubT=if true listen for change in subtree of from folder[Setup]SubT
To=The folder/directory to move the file to,
this directory is created if not exist. The filename uses the File= mask
File=filename mask in the To directory[Setup]FileFile=%fnh
Comp=The folder/directory to check the file against. If file exist in this directory and file is not the same filname will increment by _n.
Use this if you move files in stages between directories and want to check filename against the final destiniation.
In the final stage use Dupl=1 to delete duplicate files but still process on the way. For very special uses...
Exif=Set Exif=1 to adjust filedate according to exif datetime
Drop=Set Drop=1 to delete file after commands App1..App6 is executedDrop=0
Dupl=Set Dupl=1 to execute commands even if file already exists,
file is tested with name, size and Crc32, original file is deleted
Cop1=Copy a file before App1 is run
Cop1=c:\dir\file.txt c:\dir\%yyyy\%fil.txt
App1=The command to run on the file
Cmd1=Parameters to the command
Dir1=The directory to run the command in
Pri1=Priority class for individual application[Name]Prio
Appn=You can use App1,App2..App6 up to six commands per file...
(with Copn,Cmdn and Dirn)

Ext1=To deside by extension which directory to copy file
can be a list with semicolons
ToD1=If extension in list Ext1, move to directory ToD1 c:\home\web\office
Extn=You can use Ext1..Ext6 for control.

Replacable parameters in the above commands

To, File, Comp, Cmdn, Dirn you can use the following parameters:
A picture file taken 2005-apr-08: img_0123.jpg
is dropped 2014-dec-24 in the imgref directory
The section below handles the file for the "result" below
returns content of fileone line, (max 32kb)
returns 'source' directory
the %srcpath2 vars can be refered later in a chain
%srcpath2=project_23 for c:\home\web\upload\img\project_23\
returns root/root directory%srcpath3=img for c:\home\web\upload\img\project_23\
%srcpath4returns root/root/root directory%srcpath4=upload for c:\home\web\upload\img\project_23\
returns last part of 'source' directory delimited by underscore%fdd=23 for c:\home\web\upload\img\project_23\
%fdbreturns 'source', 'part -2' %fdb=img for c:\home\web\upload\img\project_23\
%filthe 'target' filename, without path or extension050408_img0123_001
%fpureturns 'target' unix pathc:/home/nav/web/upload/img/
%fpreturns 'target' pathc:\home\web\web\upload\img\
%fureturns 'target' file, unix path, no ext.c:/home/nav/web/upload/img/050408_img0123_001
%freturns 'target' filec:\home\web\web\upload\img\050408_img0123_001.jpg
%fnrureturns uppercase filenumber of orginal filename (max 16, se note)IMG0123
%fnrreturns filenumber of orginal filename (max 16, se note)img0123
%fnhreturns translated filename, only [a..z,0..9,_]img_0123
%fnoreturns orignal filename with extensionimg_0123.jpg
%fnreturns orignal filename without extensionimg_0123
%fh2returns small hash from filename+filesize, 2 charsAA
%fh3returns small hash from filename+filesize, 3 charsAAA
%fh4returns small hash from filename+filesize, 4 charsAAAA
%fereturns extension.jpg
%fcreturns file counter, if file exists 00..ZZ.
note, that if file exists and Dupl=0
then filename appends with _n where n=1.. ex. filename_12.ext
%random2returns random 00..zzx8
%random3returns random 000..zzzx8y
%random4returns random 0000..zzzzx8y4
%usrreturns current windows username
%resnnnreturns resolution needed to get nnn pixels (for .eps...)-r%res600
%rotreturns rotation of picture file if found for .jpg,.jpeg,.tif,.tiff-rotate 90
%rreturns orientation of picture file 0,6(=90),8(=-90)6
%pxreturns pixel width of image1024
%pyreturns pixel height of image768
%year2Current year, 2 digits, yy14
%year4Current year, 4 digits, yyyy2014
%date4Current date, 4 digits, yymm1412
%date6Current date, 6 digits, yymmdd141224
%date8Current date, 8 digits, yyyymmdd20141224
%date10Current date, 10 digits, yyyy-mm-dd2014-12-24
%time2Current time, 2 digits, hh14
%time4Current time, 4 digits, hhmm1445
%time6Current time, 6 digits, hhmmss144515
%time8Current time, 8 digits, hh:mm:ss14:45:15
%now8Current time, 8 digits, yymmddhh14122414
%now10Current time, 10 digits, yymmddhhmm1412241445
%now11Current time, 11 digits, yymmdd-hhmm141224-1445
%now12Current time, 12 digits, yymmddhhmmss141224144515
%now13Current time, 13 digits, yymmdd-hhmmss141224-144515
%now16Current time, 16 digits, yyyy-mm-dd_hh-mm2014-12-24_14-45
%now19Current time, 19 digits, yyyy-mm-dd_hh-mm-ss2014-12-24_14-45-15
Filedate, se note below
%yyyyDisplays the year as a four-digit number (0000-9999)2005
%yyDisplays the year as a two-digit number (00-99).
%mmmmDisplays the month as a full name (January-December)April
%mmmDisplays the month as an abbreviation (Jan-Dec)Apr
%mmDisplays the month as a number with a leading zero (01-12)04
%mDisplays the month as a number without a leading zero (1-12)4
%ddddddDisplays the date using the format given by the LongDateFormat
%dddddDisplays the date using the format given by the ShortDateFormat
%ddddDisplays the day as a full name (Sunday-Saturday)
%dddDisplays the day as an abbreviation (Sun-Sat)
%ddDisplays the day as a number with a leading zero (01-31)
%dDisplays the day as a number without a leading zero (1-31)
%cDisplays the date using the format given by the ShortDateFormat,
followed by the time using the format given by the LongTimeFormat
%hhDisplays the hour with a leading zero (00-23)
%hDisplays the hour without a leading zero (0-23)
%nnDisplays the minute with a leading zero (00-59)
%nDisplays the minute without a leading zero (0-59)
%ssDisplays the second with a leading zero (00-59)
%sDisplays the second without a leading zero (0-59)


Note on "filenumber"


If you have LogL>2 than all .jpg and .tif profiles will append to chkmagick.prf


This example handles the transformation of pictures after uploaded to a webserver, either by http, ftp or file copy I uses the ImageMagick package to transform pictures and saves the information in a mysql database.


Cmd1=%f -quality 40 -thumbnail 120 %rot %fil.jpg

Cmd2=%f -resize 600 %rot -interlace line %fil.jpg

Cmd3=%f -resize 896 %rot -interlace line %fil.jpg

Cmd4=-quality 60 -interlace line %f


cmd1=-D test -e "INSERT img (src,extt,exts,extl,exto,ori,path,nr,dat) VALUES ('%fil','.jpg','.jpg','.jpg','%fe','%r','%yyyy','%fnru','%yyyy-%mm-%dd %hh:%nn:%ss');_
 UPDATE img,imgref SET,img.prjid=imgref.prjid,img.txt=imgref.txt WHERE (img.src='%fil') and (imgref.fn='%fno');_
 UPDATE img SET ix=concat_ws(' ',concat('#',id),nr,'%yyyy','%yy%mm%dd',txt,src) WHERE src='%fil';"

Versions / Change-Log

2014-okt-17, version 2.33
%now variables
2014-jul-04, version 2.32
[Section]Kill option to terminate process if timeout is reached
2013-oct-29, version 2.30
Lots of small fixes, same config-file format, updating the web page with latest version
2009-aug-03, version 1.0
Small File Hashes now implemented
2007-feb-07, version 0.24
Exif= directive now implemented
more robust engine.
2006-jun-27, version 0.??
Copn= directive now implemented
2006-jun-19, version 0.13
Prio= directive now implemented
SubT= directive now implemented
%fd implemented
2006-jan-16, version 0.10.1
Comp= directive now implemented
2006-jan-04, version 0.9.1
Logfile moved files filename now correct
%fnr and %fnru max 16char
2005-dec-12, version 0.9
Wordwrap lines, end lines with _.
Comments, lines starting with: #, ., rem , [-- , [==
Eventlog support. Start / stop / errors
2005-okt-30, version 0.8
Moveto folder controlable by file extensions
2005-okt-24, version 0.7
Allow readonly files in listen folder, the readonly flag is turned off.
2005-sep-06, version 0.5
%fu, %fpu added
2005-jun-22, version 0.4
Initial release

More info

if you like we can help you with more template options...

More info/questions from: Subject: ChkMagick

Server,Windows,NT,2000,XP,2003,2008,Windows7,Win7,Windows8,Win8,Win32,x86, Check,Change,Monitor,DirectoryMonitor,FolderMonitor, HotFolder,Hot,MoveFiles,MoveFile,ChkFolder,ListenFolder,Listen,ChkDir,Dir,Directory,Folder,Copy,Move, FindFirstChangeNotification,ChangeNotification, ChkMagick,ImageMagick,Auto,Automatic,Empty,Notify,Check