Scheduled process to print and delete

Hello,

Is there a way to monitor the contents of a folder (PDF files) on a scheduled task to print to a printer and delete (the file) after successful print? The line of business will dump PDF reports into a folder - I want a scheduled task to monitor this folder, print, and delete.

Thoughts?

Thanks.
Evan FiddlerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jawa29Commented:
Hi,

This is straight forward enough to achieve using VBScript & Windows Scheduled Tasks.

This code will process files within a target folder, if the file is a PDF then it will, using the Wscript Shell object run the Acrobat Reader executable with some command line parameters.

It will print the documents to the default printer on the machine.
On Error Resume Next

' Set a String value to the path of the folder to be processed
FolderToMonitor = "C:\MyDev"

' Set the File System Object so we can access Folders and Files
Set FileSystemObject = CreateObject("Scripting.FileSystemObject")

' Get the Folder to be processed so we can use the item within it
Set Folder = FileSystemObject.GetFolder(FolderToMonitor)

' Get all the files currently in the folder
Set Files = Folder.Files
	
' Loop throuhg the list of files
For Each File In Files

	' Get the File Name
	FileName = File.Name
	
	' Check that the file is a PDF
	If Right(UCase(FileName), 3) = "PDF" Then
		
		' Clear any error codes
		Err.Clear
		
		' Set and use the Wscript Shell object to run a command
		Set WscriptShell = CreateObject ("Wscript.Shell")
		WscriptShell.run """C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe"" /p /h" & FileName,,True
		
		' If the Err Number returned is 0 (Success) then delete the file
		If Err.Number = 0 Then
			FileSystemObject.DeleteFile FileName
		End If
		
	End If

' Move on to the next file	
Next

Open in new window

0
Evan FiddlerAuthor Commented:
jawa29 - thanks much for your response.

I used your script but unfortunately it neither prints not deletes the files. I've added to display msgbox each step of the script and it hits all the loops and captures file name etc. The Err.Number value returned is also 0, however, nothing prints not deletes. Any thoughts?

Also, is it possible to specify the printer as well?
0
Evan FiddlerAuthor Commented:
Also, I do get "There was an error opening this document. This file cannot be found." error message when I run the script and it launches Adobe Reader.Capture.JPG
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Evan FiddlerAuthor Commented:
I've used this script instead:

strComputer = "."
TargetFolder = "C:\Files\ToPrint\" 
Set objShell = CreateObject("Shell.Application") 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objShell.Namespace(TargetFolder) 
Set colItems = objFolder.Items 

For Each objItem In colItems 
	FileName = objItem.Name

	objItem.InvokeVerbEx ("Print") 

	WScript.Sleep(10000)

	objFSO.DeleteFile(TargetFolder & FileName), True

Next 

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jawa29Commented:
Hi there,

I'm glad you found a solution, I will look at why my script didn't work for my own curiosity.
0
Evan FiddlerAuthor Commented:
My answer is what I was looking for. jawa29 did help with ideas for me to get there.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.