Using CmdTwain in a Batch File

Here’s another user submitted example, this time showing one way of using CmdTwain in a batch file …

Greg,

Thank you! This reply was so much better than I could have ever hoped for!

I’ve written a little batch script to launch CmdTwain in the way I want – had a couple of kinks, and I’m fairly sure there must be better ways of doing some of the things, but I’m quite pleased with the fact that it works! I have included it – you are welcome to use, modify, redistribute, etc. (I hope to see it included with the next release of CMDTwain ;-))

Cheers,

 

Dave
www.tamingit.com

 

@echo on
title Launching Scanner

rem � Taming IT 2008

set res=200
rem sets scan resolution - Default = 200
rem Brother MFC-7420 supports up to 1200

set out=JPG75
rem sets file type/compression - Default = JPG75
rem Options: BMP, JPG25, JPG50, JPG75, and JPG100

set dir=D:\NCH\Scanned Docs\
rem directory to place scanned files. needs final \

set cmdtwain=c:\Program Files\GssSoftware\CmdTwain\cmdtwain.exe
rem path to cmdtwain

set scancount=c:\Program Files\GssSoftware\CmdTwain\scancount.dat
rem path to scancount.dat

set errdest=localhost
rem destination for errors sent using net send

if not exist "%scancount%" (
echo 1 > "%scancount%"
attrib +R +S +H "%scancount%"
)
rem creates and secures scancount.dat if it doesn't exist

for /F "tokens=*" %%i in (%scancount%) do set fid=%%i
rem gets file id number from scancount.dat

echo Resolution = %res%
echo Format = %out%
echo Save Directory = %dir%
echo File Count = %fid%

if exist "%dir%00000%fid%.jpg" goto reset else (
if exist "%dir%0000%fid%.jpg" goto reset else (
if exist "%dir%000%fid%.jpg" goto reset else (
if exist "%dir%00%fid%.jpg" goto reset else (
if exist "%dir%0%fid%.jpg" goto reset else (
if exist "%dir%%fid%.jpg" goto reset else (
goto callct
))))))
:reset
net send %errdest% Please call Dave re scanner failure - 07958 006519 - Please Quote --File Exists--
echo File already exists
goto end
rem errors and closes if destination file already exists

:callct
if /i %fid% LEQ 9 %cmdtwain% /DPI=%res% /%out% %dir%00000%fid%.jpg else (
if /i %fid% LEQ 99 %cmdtwain% /DPI=%res% /%out% %dir%0000%fid%.jpg else (
if /i %fid% LEQ 999 %cmdtwain% /DPI=%res% /%out% %dir%000%fid%.jpg else (
if /i %fid% LEQ 9999 %cmdtwain% /DPI=%res% /%out% %dir%00%fid%.jpg else (
if /i %fid% LEQ 99999 %cmdtwain% /DPI=%res% /%out% %dir%0%fid%.jpg else (
if /i %fid% LEQ 999999 %cmdtwain% /DPI=%res% /%out% %dir%%fid%.jpg else (
net send %errdest% Please call Dave re scanner failure - 07958 006519 - Please Quote --Number too big--
echo Number too big
goto end
))))))
rem calls cmdtwain and passes file name. errors and closes if %fid% > 999999.

set /a fid=fid+1
attrib -R -S -H "%scancount%"
echo %fid% > "%scancount%"
attrib +R +S +H "%scancount%"
rem increments file id and moves back into scancount.dat

:end
pause

 

Disclaimer

The example provided here is free of charge but it is also without warranty of any kind. The user is responsible for determining its suitability or otherwise for their particular needs. Neither the authors, nor GssEziSoft, accept liability for any problems arising out of the use of the example program.

Download the Example

Right click and Save the example code.

Download CmdTwain

You can also download CmdTwain for free.

Leave a Reply

Your email address will not be published. Required fields are marked *