Command line batch print - HOWTO

B

Barry

No help needed, just uploading info after my longish search so other
can make use of this :D


I needed a way to batch print a load of word docs in a folder, using a
batch file.

Just create a batch file and load the code into it.
Dobule click or run the file and all docs will be sent to printer and
closed in sequence.
(You do of course need word installed to do this)

Here's the code:

==========================

cls

rem create batch file that runs word
echo "c:\Program Files\Microsoft Office\Office10\winword.exe" %%1 /a
/mfileprintdefault /mFileExit > wordprint.bat
echo move %%1 printed\%%1 >> wordprint.bat

rem create a directory listing of word docs
dir /b *.doc > dirlist.txt

rem print and move the docs using created batch file
for /F %%a in (dirlist.txt) do wordprint.bat %%a


rem cleanup
del dirlist.txt
del wordprint.bat


echo
echo finished !!

==========================
 
B

Barry

slightly improved, with error handling

===========================

echo off
cls

rem create printed subfolder
md printed

rem create a directory listing of word docs
dir /b *.doc > dirlist.txt

rem print and move the docs using created batch file
for /F "delims=," %%a in (dirlist.txt) do (
"c:\Program Files\Microsoft Office\Office10\winword.exe" "%%a" /a
/mfileprintdefault /mFileExit
move "%%a" "printed\%%a"
)


rem inform user of printing ok or not, and pause to allow for cleanup
cls
echo ===================
if not errorlevel 1 goto else
echo An error occurred, please check your documents (filelist opening
now).
start dirlist.txt
goto end
:else
echo All doc files sent to printer and moved to Printed folder.
:end
pause

rem cleanup
del dirlist.txt
del wordprint.bat
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top