Jump to content

(Very) basic question re: script errors


Recommended Posts

Hi,

I am new on here and was hoping you can help with what I believe is basic problem.

I am not a programmer, but chanced my arm at cobbling together some .vbs to help automate a work process. We are a printing company, I tried to write a script (executed by Windows scheduled tasks) to do the following:

1.) check a folder to see if .pdfs had been uploaded via ftp & move them to another folder ("print")

2.) print any .pdfs contained in that "print" folder to default printer (digital printer on site)

3.) delete the files

The initial "move files to print" script is as follows:

Set objFSO = CreateObject("Scripting.FileSystemObject")

objFSO.MoveFile "C:\XPC\Output\DocuPrint\*.pdf" , "C:\XPC\Output\DucuPrint_WaitingtoPrint\"

The next script (executes shortly after) is as follows:

TargetFolder = "C:\XPC\Output\DucuPrint_WaitingtoPrint\"

Set objShell = CreateObject("Shell.Application")

Set objFolder = objShell.Namespace(TargetFolder)

Set colItems = objFolder.Items

For i = 0 to colItems.Count - 1

colItems.Item(i).InvokeVerbEx("Print")

Next

The next "delete files" script is:

Dim ObjFso

Dim StrSourceLocation

Dim StrSourceFileName

StrSourceLocation = "C:\XPC\Output\DucuPrint_WaitingtoPrint"

StrSourceFileName = "*.pdf"

Set ObjFso = CreateObject("Scripting.FileSystemObject")

ObjFso.DeleteFile "C:\XPC\Output\DucuPrint_WaitingtoPrint\*.pdf"

The problem I am experiencing is when there are no files in these folders and the script executes, a Windows Script Host pop up displays, with the error "file not found" (Code: 800A0035 / Source: Microsoft VBScript runtime error)

I know this is extremely basic, however I would be deeply grateful if someone could help me tailor the scripts so we do not receive error pop ups.

Many thanks in advance!

Link to comment
Share on other sites


Are you using 3 separate scripts or just one big script with 3 procedures?

You could try changing this line in the print script

Change From


colItems.Item(i).InvokeVerbEx("Print")

Change Too


TargetFolder & colItems.Item(i).InvokeVerbEx("Print")

This change will pass a full path and File Name now instead of just the File Name

Link to comment
Share on other sites

You'd have to test if colItems is null, or its count is less than one, and then wrapping the for loop in that.

But honestly this is much simpler in PowerShell (the "modern" replacement to batch and vbscript, which also built in modern windows versions and otherwise it's free and easy to install). Your 3 scripts are 3 simple one-liners:

Script 1:


mv C:\XPC\Output\DocuPrint\*.pdf C:\XPC\Output\DucuPrint_WaitingtoPrint\

Script 2:


ls C:\XPC\Output\DucuPrint_WaitingtoPrint\*.pdf|%{start -FilePath $_.FullName -Verb Print}

Script 3:


rm C:\XPC\Output\DucuPrint_WaitingtoPrint\*.pdf

That's all of it, and you won't be getting a single error message either, even if there are no files. I willingly kept the docuprint/ducuprint inconsistency as your folders are likely named that way, so adjust that to your wishes.

That's quite a simplistic system though. It assumes you only ever want one copy and obviously no checks are done on client's PDF files i.e. is there sufficient resolution on images? are fonts embedded? are there any hairlines? (no point in me listing everything as you certainly know this stuff far better than I do). But if it does whatever you need then why not.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...