1.

Solve : batch for a multiple print job.?

Answer» <html><body><p>I know almost nothing about creating batch files.<br/><br/>For work, I have a directory of text files that each need to be printed. On a busy day there are <a href="https://interviewquestions.tuteehub.com/tag/upwards-2318352" style="font-weight:bold;" target="_blank" title="Click to know more about UPWARDS">UPWARDS</a> of 100 files in there.<br/><br/>How would I go about creating a batch file to print all files in the directory, on a network printer, preferably in alphabetical order?<br/><br/>the only information I can find on doing this <a href="https://interviewquestions.tuteehub.com/tag/says-1195457" style="font-weight:bold;" target="_blank" title="Click to know more about SAYS">SAYS</a> I need to use the command<br/><br/> Code: <a>[Select]</a>notepad /p filename.txt<br/>but that only works for one document. <br/><br/>any help on this would be most appreciated. Thanks.The following code has not been tested. <br/>I do not have the lpr1  command on my machine.<br/><br/>The code does suggest one method:<br/><br/> Code: <a>[Select]</a>echo off<br/><br/>dir *.txt | sort &gt; alltext.txt<br/><br/>for /f "delims=" %%i in (alltext.txt) do  (<br/><br/>rem echo %%i<br/><br/>print /D:lpt1 %%i<br/>)<br/>Cool. Thanks. How could I change that to work with a network printer?<br/><br/><br/><a href="https://interviewquestions.tuteehub.com/tag/also-373387" style="font-weight:bold;" target="_blank" title="Click to know more about ALSO">ALSO</a>, while waiting for a response I think I came up with something else. I'm just not sure if it will work alphabetically and I don't have a printer connected to this machine to test it.<br/><br/> Code: <a>[Select]</a>echo off<br/><br/>FORFILES /p mydir /m *.txt /c "cmd /c notepad /p":A<br/>if 0%1==0 exit<br/>notepad /p %1<br/>shift<br/>goto a<br/><br/>drag and drop all files to be printed<strong>Your "notepad /p"  works perfectly inside the for loop. <br/>All automatically and quickly</strong>.<br/>I printed only five  text files.<br/>Here is the code:<br/><br/><br/>C:&gt;type  prtxt.bat<br/><br/> Code: <a>[Select]</a>echo off<br/><br/>dir /b n*.txt  &gt; alltext.txt<br/>rem dir /b *.txt | sort  &gt; alltext.txt<br/><br/>type alltext.txt<br/><br/>for /f "delims=" %%i in (alltext.txt) do  (<br/><br/>rem echo %%i<br/>notepad /p %%i<br/><br/>)<strong>Output:</strong><br/><br/>C:&gt; prtxt.bat<br/>nc.txt<br/>new.txt<br/>NextFile.txt<br/>notepid.txt<br/>num.txt<br/><br/>C:&gt;<br/><br/>_____________________________<br/><br/>Notepad uses a HP LaserJet 1100A attached to my machine.<br/><br/>The parallel  laserjet is several years old and has a USB adapter for the Dell 530s<br/><br/>what happens if he wants to print rtf files or only certain  files in a folder <a href="https://interviewquestions.tuteehub.com/tag/quote-1175222" style="font-weight:bold;" target="_blank" title="Click to know more about QUOTE">QUOTE</a> from: mat123 on July 27, 2010, 03:54:22 PM</p><blockquote>what happens if he wants to print rtf files or only certain  files in a folder<br/></blockquote> <br/>Change:<br/><br/> dir /b *.txt | sort  &gt; alltext.txt<br/><br/>to<br/><br/> dir /b *.* | sort  &gt; alltext.txt<br/><br/>or <br/><br/> dir /b *.rtf  | sort  &gt; alltext.txt<br/>or<br/><br/><br/> dir /b *.%1 | sort  &gt; alltext.txt<br/><br/><br/><br/>After combining what I learned from your code snippets and <a href="https://ss64.com/nt/">http://ss64.com/nt/</a> I've come up with the following.<br/><br/>The only problem I have is that the "list.txt" is included in the list of files and I'm not sure how to remove that as I don't want to print it and it's deleted after the FOR /F command processes. It's not so bad as it will print a list of things in the order they're supposed to be in and that might be useful for my application, but it's still superfluous and I'm a minimalist.<br/><br/>also this doesn't require dragging and dropping. but it does require the batch to be given a hidden attribute<br/><br/> Code: <a>[Select]</a>ECHO OFF<br/>ECHO Creating Directory Listing<br/>dir /a:-h /b /-p /o:EN &gt;"list.txt"<br/><br/>ECHO Processing Directory Listing<br/>FOR /F %%i IN ("list.txt") DO (<br/><br/>REM %%i <br/><br/>notepad /p %%i<br/>)<br/><br/>ECHO Deleting Directory Listing<br/>del "list.txt"<br/><br/>ECHO Process Complete. Press a key to exit.<br/>PAUSE<br/>Now, I don't have an <a href="https://interviewquestions.tuteehub.com/tag/actual-361632" style="font-weight:bold;" target="_blank" title="Click to know more about ACTUAL">ACTUAL</a> printer to test this on. Only the windows XPS writer. Quote from: marylane on July 27, 2010, 04:04:37 PM<blockquote>Change:<br/><br/> dir /b *.txt | sort  &gt; alltext.txt<br/><br/>to<br/><br/> dir /b *.* | sort  &gt; alltext.txt<br/><br/>or <br/><br/> dir /b *.rtf  | sort  &gt; alltext.txt<br/>or<br/><br/><br/> dir /b *.%1 | sort  &gt; alltext.txt<br/></blockquote> <br/>+1<br/><br/>fantastic. thanks a lot for the help. Quote from: ErusPrime on July 27, 2010, 04:18:27 PM<blockquote>The only problem I have is that the "list.txt" is included in the list of files and I'm not sure how to remove?<br/></blockquote> <br/>findstr  /V "list.txt"  list.txt &gt; list2.txt<br/>copy  list2.txt  list.txt<br/>del list2.txt<br/><br/><br/>For example:<br/><br/><br/>C:\test&gt;type erus.bat<br/> Code: <a>[Select]</a>echo off<br/>echo  Creating Directory Listing<br/><br/>rem dir /a:-h /b /-p /o:EN &gt;"list.txt"<br/><br/>dir /b l*.txt &gt; list.txt<br/>dir /b n*.txt &gt;&gt; list.txt<br/><br/>findstr /v "list.txt"  list.txt &gt; list2.txt<br/>type list2.txt<br/>pause<br/>copy  list2.txt  list.txt<br/>del list2.txt<br/>echo type list.txt<br/>type list.txt<br/>pause<br/>ECHO Processing Directory Listing<br/>For  /F %%i in (list.txt) do  (<br/><br/>echo %%i<br/>rem notepad /p %%i<br/><br/>)<br/><br/>ECHO Deleting Directory Listing<br/>rem del "list.txt"<br/><br/>ECHO Process Complete. Press a key to exit.<br/>PAUSE<br/><strong>Output:</strong><br/>C:\test&gt;erus.bat<br/>Creating Directory Listing<br/>log.txt<br/>nc.txt<br/>new.txt<br/>NextFile.txt<br/>notepid.txt<br/>num.txt<br/>Press any key to continue . . .<br/>        1 file(s) copied.<br/>type list.txt<br/>log.txt<br/>nc.txt<br/>new.txt<br/>NextFile.txt<br/>notepid.txt<br/>num.txt<br/>Press any key to continue . . .<br/>Processing Directory Listing<br/>log.txt<br/>nc.txt<br/>new.txt<br/>NextFile.txt<br/>notepid.txt<br/>num.txt<br/>Deleting Directory Listing<br/>Process Complete. Press a key to exit.<br/>Press any key to continue . . .<br/>C:\test&gt;okay. I think that makes sense.<br/><br/>I need all the files though and not just l*.txt and n*.txt<br/><br/>are the pauses absolutely necessary? sometimes the list is going to be more than 100 lines long. or is that just a "look how it works" kinda thing? Quote from: ErusPrime on July 27, 2010, 07:16:16 PM<blockquote>okay. I think that makes sense.<br/><br/>I need all the files though and not just l*.txt and n*.txt<br/><br/>are the pauses absolutely necessary? sometimes the list is going to be more than 100 lines long. or is that just a "look how it works" kinda thing?<br/></blockquote> <br/>The pauses are not necessary.  It was used while testing.<br/><br/>I noticed your code got all files and also all directories.  How do you print a directory with notepad?  Also *.exe files will not print with notepad.<br/><br/>I have never used may of the dir options in your batch file so I'm not sure what files you are after.  I thought you were only after *.txt  files?<br/><br/>I'm not sure what this line does:<br/><br/>dir /a:-h /b /-p /o:EN &gt;"list.txt"<br/><br/>It appears you get more files than needed?<br/><br/>Good luck<br/><br/></body></html>


Discussion

No Comment Found