Printing multiple files in order

fanch_22 Posted messages 1 Status Member -  
pcturbo Posted messages 581 Status Contributor -
Hello,

Here is my problem.

I have more than 1,500 Outlook files to print in chronological order. I had to extract them from Outlook to copy them into a folder on a USB drive. And it is from this folder that I need to start printing, selecting all, in order to get all pages in a bulk at the printer output in chronological order.

The problem is that when I print, the pages come out in a random order. I tried sorting by "Details" in Windows and then by creation date (during the transfer from Outlook to the folder, the chronological order of the emails was preserved, even if the date and time correspond to the copy/paste and not to reality). That does not affect the printer output. I tried with another printer and it's the same.

I don't understand the order of the pages coming out of the printer; it's not alphabetical order, nor file size...

Would someone have a solution???

Thanks for your responses

1 answer

pcturbo Posted messages 581 Status Contributor 200
 
Hello,

I propose the following solution, which can be adapted for similar needs, namely: printing a series of files of the same type (supported by the same application) and in a specific order. This solution is valid for any type of file for which the application allows printing to be launched from the command line. In your case it is MS Outlook. Since you did not specify your operating system (MAC, Windows, Linux, ...) or its version, nor the version of Outlook, the solution below is valid for Windows 64bit 7 or 8 and MS Outlook 2010 (MS Office 14). This should work for .msg files exported from Outlook.

The peculiarity of the problem is to ensure the print order of the files. As you have observed, selecting a series of files in Windows Explorer and ordering printing does not guarantee the processing order. It is therefore a matter of passing the files one by one to the application, and automating the process.

To do this, we will create two files, one that will contain the list of files, in the desired order; the other will contain a small program.

Preparation of the file list.
Prepare a folder that contains all the files to be printed, and no others. To simplify subsequent manipulations, I recommend placing this folder at the root of the drive (or USB key) and giving it a short name with no spaces. I will use the folder "F:\messages" as an example. It will also be easier if the file names contain no spaces.
The file will be a plain text file and will contain one file name per line. To create it, open a Windows command prompt window, then use a command that will write the list of files automatically.
- press the [Windows] and [R] keys
- in the Run box, type "cmd" (without quotes) and press Enter
- Windows will show a command prompt
- type "F:" (or the drive letter of your USB drive) and press Enter
- type "cd \messages" and press Enter (adjust the path if different)
- type "dir /B *.msg > listemsg.txt" and press Enter
- Windows will create in the same folder a file listemsg.txt that contains the list of all .msg files in alphabetical order. If you need a different order, reuse this file with a tool you master.

Printer identification.
We will need the name of your printer. Open the list of printers, right-click the printer you want to use, choose Properties and carefully note the printer name. You can come back here and copy-paste it when needed.

Preparation of the program file
Keep the command prompt window open, and launch Notepad. For example, press the Windows and R keys, then type notepad and confirm.
In this new text file, copy-paste the 12 lines of text/code shown below:

@echo off
:debut
FOR /F "delims=," %%i IN (listemsg.txt) DO (
"c:\program files (x86)\microsoft office\office14\outlook.exe" /p "F:\messages\%%i" lenomdevotreimprimante
if errorlevel 0 (
echo %%i est en cours d'impression.
timeout /T 4 >nul
) ELSE (
echo Un problème s'est produit pendant l'impression de %%i.
)
)
echo Fin de l'impression des messages.

Note: what is shown on lines 4 and 5 above should actually form a single line. I count it as a single line in my notes below.

Correct line 3 if you used another filename for the list (listemsg.txt).
Correct line 4 the path to the F:\messages folder if it is not that path. Do not modify the folder path structure (quotes, backslashes following, etc.)
Mandatory: in line 4 replace lenomdevotreimprimante with the name of your printer. If the name contains spaces, enclose it in quotes.
Save this new file you are creating in the same folder F:\messages (or your own) under the name impmsg.cmd

Testing and Modifications
I recommend doing a test with a copy of the list file that contains only 3 lines (three messages to print).
You may also need to adjust:
- line 4 of the program if Outlook is not installed at that location (different version, Windows XP, ...). This line must start with the full path to the executable in quotes.
- line 7 contains a command that gives Outlook time to handle the command before sending the next file. I set the value to 4 (seconds), but if you notice messages are not printed in order you will need to increase it.

How to start printing
Return to the Windows command box. Check that the prompt shows the path to the folder F:\messages> (or the path to your folder).
Type impmsg and press Enter. impmsg is the name of your program file.

Good luck.

For advanced users:
To use this for other file types whose printing is command-line driven, simply collect the information on the command and options. For example, for Adobe Reader version 11 to print a batch of PDFs, you would upload the following:
"C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe" /h /t "F:\messages\%%i" lenomdevotreimprimante
The value of timeout must be greater than the time between the execution of line 4 and the response obtained by errorlevel. The errorlevel response is not issued at the end of every print (at least for AcroRd32); it is given at the start, as soon as the file has been read. Without a timeout, Windows does not wait and sends everything blindly, and the result is that the server application will rather process the last file first, or as it can... and memory issues may occur. The timeout helps regulate the flow and guarantee the order.
-1
pcturbo Posted messages 581 Status Contributor 200
 
IMPORTANT - a small oversight: before running the impmsg command, launch Outlook if the application is not already running (then set it aside, minimize it for example), otherwise the script will be blocked after printing each file (Windows will wait for the Outlook instance that was launched to be closed).
0
pcturbo Posted messages 581 Status Contributor 200 > pcturbo Posted messages 581 Status Contributor
 
Sorry, two corrections. 1) Please ignore my second message; there is no need to launch Outlook beforehand. However, if we use the technique with Adobe Reader, then it is necessary. 2) In the program, line 4, ignore the last parameter "lenomdevotreimprimante". Outlook does not handle it (it is a parameter valid for Adobe Reader). Outlook sends to the default printer. Therefore, you should set the printer to use as the default printer before starting the print. The program code is therefore:
@echo off
:debut
FOR /F "delims=," %%i IN (listemsg.txt) DO (
"c:\program files (x86)\microsoft office\office14\outlook.exe" /p "F:\messages\%%i"
if errorlevel 0 (
echo %%i est en cours d'impression.
timeout /T 4 >nul
) ELSE (
echo Un problème s'est produit pendant l'impression de %%i.
)
)
echo Fin de l'impression des messages.
-1