1.

Solve : batch for a multiple print job.?

Answer»

I know almost nothing about creating batch files.

For work, I have a directory of text files that each need to be printed. On a busy day there are UPWARDS of 100 files in there.

How would I go about creating a batch file to print all files in the directory, on a network printer, preferably in alphabetical order?

the only information I can find on doing this SAYS I need to use the command

Code: [Select]notepad /p filename.txt
but that only works for one document.

any help on this would be most appreciated. Thanks.The following code has not been tested.
I do not have the lpr1  command on my machine.

The code does suggest one method:

Code: [Select]echo off

dir *.txt | sort > alltext.txt

for /f "delims=" %%i in (alltext.txt) do  (

rem echo %%i

print /D:lpt1 %%i
)
Cool. Thanks. How could I change that to work with a network printer?


ALSO, 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.

Code: [Select]echo off

FORFILES /p mydir /m *.txt /c "cmd /c notepad /p":A
if 0%1==0 exit
notepad /p %1
shift
goto a

drag and drop all files to be printedYour "notepad /p"  works perfectly inside the for loop.
All automatically and quickly
.
I printed only five  text files.
Here is the code:


C:>type  prtxt.bat

Code: [Select]echo off

dir /b n*.txt  > alltext.txt
rem dir /b *.txt | sort  > alltext.txt

type alltext.txt

for /f "delims=" %%i in (alltext.txt) do  (

rem echo %%i
notepad /p %%i

)Output:

C:> prtxt.bat
nc.txt
new.txt
NextFile.txt
notepid.txt
num.txt

C:>

_____________________________

Notepad uses a HP LaserJet 1100A attached to my machine.

The parallel  laserjet is several years old and has a USB adapter for the Dell 530s

what happens if he wants to print rtf files or only certain  files in a folder QUOTE from: mat123 on July 27, 2010, 03:54:22 PM

what happens if he wants to print rtf files or only certain  files in a folder

Change:

 dir /b *.txt | sort  > alltext.txt

to

 dir /b *.* | sort  > alltext.txt

or

 dir /b *.rtf  | sort  > alltext.txt
or


 dir /b *.%1 | sort  > alltext.txt



After combining what I learned from your code snippets and http://ss64.com/nt/ I've come up with the following.

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.

also this doesn't require dragging and dropping. but it does require the batch to be given a hidden attribute

Code: [Select]ECHO OFF
ECHO Creating Directory Listing
dir /a:-h /b /-p /o:EN >"list.txt"

ECHO Processing Directory Listing
FOR /F %%i IN ("list.txt") DO (

REM %%i

notepad /p %%i
)

ECHO Deleting Directory Listing
del "list.txt"

ECHO Process Complete. Press a key to exit.
PAUSE
Now, I don't have an ACTUAL printer to test this on. Only the windows XPS writer. Quote from: marylane on July 27, 2010, 04:04:37 PM
Change:

 dir /b *.txt | sort  > alltext.txt

to

 dir /b *.* | sort  > alltext.txt

or

 dir /b *.rtf  | sort  > alltext.txt
or


 dir /b *.%1 | sort  > alltext.txt

+1

fantastic. thanks a lot for the help. Quote from: ErusPrime on July 27, 2010, 04:18:27 PM
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?

findstr  /V "list.txt"  list.txt > list2.txt
copy  list2.txt  list.txt
del list2.txt


For example:


C:\test>type erus.bat
Code: [Select]echo off
echo  Creating Directory Listing

rem dir /a:-h /b /-p /o:EN >"list.txt"

dir /b l*.txt > list.txt
dir /b n*.txt >> list.txt

findstr /v "list.txt"  list.txt > list2.txt
type list2.txt
pause
copy  list2.txt  list.txt
del list2.txt
echo type list.txt
type list.txt
pause
ECHO Processing Directory Listing
For  /F %%i in (list.txt) do  (

echo %%i
rem notepad /p %%i

)

ECHO Deleting Directory Listing
rem del "list.txt"

ECHO Process Complete. Press a key to exit.
PAUSE
Output:
C:\test>erus.bat
Creating Directory Listing
log.txt
nc.txt
new.txt
NextFile.txt
notepid.txt
num.txt
Press any key to continue . . .
        1 file(s) copied.
type list.txt
log.txt
nc.txt
new.txt
NextFile.txt
notepid.txt
num.txt
Press any key to continue . . .
Processing Directory Listing
log.txt
nc.txt
new.txt
NextFile.txt
notepid.txt
num.txt
Deleting Directory Listing
Process Complete. Press a key to exit.
Press any key to continue . . .
C:\test>okay. I think that makes sense.

I need all the files though and not just l*.txt and n*.txt

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
okay. I think that makes sense.

I need all the files though and not just l*.txt and n*.txt

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?

The pauses are not necessary.  It was used while testing.

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.

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?

I'm not sure what this line does:

dir /a:-h /b /-p /o:EN >"list.txt"

It appears you get more files than needed?

Good luck



Discussion

No Comment Found