{"id":112,"date":"2009-06-04T12:54:29","date_gmt":"2009-06-04T12:54:29","guid":{"rendered":"http:\/\/www.gssezisoft.com\/main\/?p=112"},"modified":"2015-02-02T04:34:44","modified_gmt":"2015-02-02T04:34:44","slug":"using-cmdtwain-in-a-batch-file","status":"publish","type":"post","link":"http:\/\/www.gssezisoft.com\/main\/2009\/06\/using-cmdtwain-in-a-batch-file\/","title":{"rendered":"Using CmdTwain in a Batch File"},"content":{"rendered":"<p>Here&#8217;s another user submitted example, this time showing one way of using CmdTwain in a batch file &#8230;<!--more--><\/p>\n<p>Greg,<\/p>\n<p>Thank you! This reply was so much better than I could have ever hoped for!<\/p>\n<p>I&#8217;ve written a little batch script to launch CmdTwain in the way I want &#8211; had a couple of kinks, and I&#8217;m fairly sure there must be better ways of doing some of the things, but I&#8217;m quite pleased with the fact that it works! I have included it &#8211; you are welcome to use, modify, redistribute, etc. (I hope to see it included with the next release of CMDTwain ;-))<\/p>\n<p>Cheers,<\/p>\n<p>&nbsp;<\/p>\n<p>Dave<br \/>\n<a href=\"http:\/\/www.tamingit.com\">www.tamingit.com<\/a><\/p>\n<p>&nbsp;<\/p>\n<div style=\"width: 600; border: 1px solid black; overflow: scroll;\">\n<pre>\r\n@echo on\r\ntitle Launching Scanner\r\n\r\nrem \ufffd Taming IT 2008\r\n\r\nset res=200\r\nrem sets scan resolution - Default = 200\r\nrem Brother MFC-7420 supports up to 1200\r\n\r\nset out=JPG75\r\nrem sets file type\/compression - Default = JPG75\r\nrem Options: BMP, JPG25, JPG50, JPG75, and JPG100\r\n\r\nset dir=D:\\NCH\\Scanned Docs\\\r\nrem directory to place scanned files. needs final \\\r\n\r\nset cmdtwain=c:\\Program Files\\GssSoftware\\CmdTwain\\cmdtwain.exe\r\nrem path to cmdtwain\r\n\r\nset scancount=c:\\Program Files\\GssSoftware\\CmdTwain\\scancount.dat\r\nrem path to scancount.dat\r\n\r\nset errdest=localhost\r\nrem destination for errors sent using net send\r\n\r\nif not exist \"%scancount%\" (\r\necho 1 &gt; \"%scancount%\"\r\nattrib +R +S +H \"%scancount%\"\r\n)\r\nrem creates and secures scancount.dat if it doesn't exist\r\n\r\nfor \/F \"tokens=*\" %%i in (%scancount%) do set fid=%%i\r\nrem gets file id number from scancount.dat\r\n\r\necho Resolution = %res%\r\necho Format = %out%\r\necho Save Directory = %dir%\r\necho File Count = %fid%\r\n\r\nif exist \"%dir%00000%fid%.jpg\" goto reset else (\r\nif exist \"%dir%0000%fid%.jpg\" goto reset else (\r\nif exist \"%dir%000%fid%.jpg\" goto reset else (\r\nif exist \"%dir%00%fid%.jpg\" goto reset else (\r\nif exist \"%dir%0%fid%.jpg\" goto reset else (\r\nif exist \"%dir%%fid%.jpg\" goto reset else (\r\ngoto callct\r\n))))))\r\n:reset\r\nnet send %errdest% Please call Dave re scanner failure - 07958 006519 - Please Quote --File Exists--\r\necho File already exists\r\ngoto end\r\nrem errors and closes if destination file already exists\r\n\r\n:callct\r\nif \/i %fid% LEQ 9 %cmdtwain% \/DPI=%res% \/%out% %dir%00000%fid%.jpg else (\r\nif \/i %fid% LEQ 99 %cmdtwain% \/DPI=%res% \/%out% %dir%0000%fid%.jpg else (\r\nif \/i %fid% LEQ 999 %cmdtwain% \/DPI=%res% \/%out% %dir%000%fid%.jpg else (\r\nif \/i %fid% LEQ 9999 %cmdtwain% \/DPI=%res% \/%out% %dir%00%fid%.jpg else (\r\nif \/i %fid% LEQ 99999 %cmdtwain% \/DPI=%res% \/%out% %dir%0%fid%.jpg else (\r\nif \/i %fid% LEQ 999999 %cmdtwain% \/DPI=%res% \/%out% %dir%%fid%.jpg else (\r\nnet send %errdest% Please call Dave re scanner failure - 07958 006519 - Please Quote --Number too big--\r\necho Number too big\r\ngoto end\r\n))))))\r\nrem calls cmdtwain and passes file name. errors and closes if %fid% &gt; 999999.\r\n\r\nset \/a fid=fid+1\r\nattrib -R -S -H \"%scancount%\"\r\necho %fid% &gt; \"%scancount%\"\r\nattrib +R +S +H \"%scancount%\"\r\nrem increments file id and moves back into scancount.dat\r\n\r\n:end\r\npause\r\n\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<h2>Disclaimer<\/h2>\n<p>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.<\/p>\n<h1>Download the Example<\/h1>\n<p>Right click and Save the <a href=\"http:\/\/www.gssezisoft.com\/Products\/CmdTwain\/Examples\/eg0001.txt\" target=\"_blank\">example code<\/a>.<\/p>\n<h1>Download CmdTwain<\/h1>\n<p>You can also <a href=\"http:\/\/www.gssezisoft.com\/main\/get-cmdtwain-free\/\">download CmdTwain<\/a> for free.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s another user submitted example, this time showing one way of using CmdTwain in a batch file &#8230;<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[7,38],"tags":[],"_links":{"self":[{"href":"http:\/\/www.gssezisoft.com\/main\/wp-json\/wp\/v2\/posts\/112"}],"collection":[{"href":"http:\/\/www.gssezisoft.com\/main\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gssezisoft.com\/main\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gssezisoft.com\/main\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gssezisoft.com\/main\/wp-json\/wp\/v2\/comments?post=112"}],"version-history":[{"count":0,"href":"http:\/\/www.gssezisoft.com\/main\/wp-json\/wp\/v2\/posts\/112\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.gssezisoft.com\/main\/wp-json\/wp\/v2\/media?parent=112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gssezisoft.com\/main\/wp-json\/wp\/v2\/categories?post=112"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gssezisoft.com\/main\/wp-json\/wp\/v2\/tags?post=112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}