Link to home
Start Free TrialLog in
Avatar of vpnsol123
vpnsol123

asked on

VBScript to print and move files

I need a VBScript that will send all text files in a specified folder to the default printer.  Once each document is printed, I need that document moved to a "processed" folder.
Avatar of Bill Prew
Bill Prew

Here is a starting point that should be close.  Test it there and see how it goes.  Save as a VBS file and edit the two paths near the top to be your locations.  Run as follows from a command prompt:

cscript ee29097954.vbs

I'm not sure if moving the files immediately after they have been queued for printing will work, there's a chance that moving them before they finish printing make cause a problem, don't know so test it out.  I don't know an easy way to check the print queue to know when each file finishes printing...

An alternate approach would be to queue them all for printing, then pause the script and when the user sees they all printed, have them "press any key to continue" and then move all the files then.

Option Explicit

' Specify folder locations
Const strBaseDir = "b:\ee\ee29097954\files"
Const strDoneDir = "b:\ee\ee29097954\done"

' Declare global variables
Dim objFSO, objShell
Dim objFolder, objFile

' Create needed objects
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Shell.Application")

' Quit if needed folders don't exist
If Not objFSO.FolderExists(strBaseDir) Then
    Wscript.Echo Now & " ERROR: Base folder """ & strBaseDir & """ does not exist, quiting."
    Wscript.Quit
End If
If Not objFSO.FolderExists(strDoneDir) Then
    Wscript.Echo Now & " ERROR: Processed folder """ & strDoneDir & """ does not exist, quiting."
    Wscript.Quit
End If

' Process each file, printing it, then moving to processed folder
Set objFolder = objShell.Namespace(strBaseDir) 
For Each objFile in objFolder.Items
    objFile.InvokeVerbEx("Print")
    objFSO.MoveFile objFile.Path, strDoneDir & "\"
Next

' Done
Wscript.Quit

Open in new window


»bp
Avatar of vpnsol123

ASKER

It did error.  It moved the files but had an issue printing them.  If there were a way to queue them all up first, that would work.

Thanks,
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial