VBS Script – Printing all Images in a Folder

Here is just a little Visual Basic script I had to put together the other day. The whole thing or parts may be useful to people so I thought I would post it.

The script looks at each file in a specified folder and checks if it is a “Tiff image”, if it is then an application is called to print the file and then the file is moved so another folder.

The script could easily be adapted for other file types or different tasks other than printing.

For this script I am using IrfranView to print the images mainly because it is free image viewer, it has a /print and /silent switch and I already had it installed :).

If like me you are printing a multi page tif or pdf and find that IrfanView with the /slient switch only prints the first page you need to print one image though the GUI first there is a little option on the print window to print all page the default is only the first (weird).

This option gets saved it an ini file and is used by the /slient mode

On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
varInputPath = "c:\source folder"
varOutputPath = "c:\destination folder"
Set FolderToPrint = objFSO.GetFolder(varInputPath)
Set FilesToPrint = FolderToPrint.Files
For Each file in FilesToPrint
        varFileName = file.name
        varFileType = file.type
        if varFileType = "TIF Image" Then
                'Print the File
                CMDRun = AddQuotes("C:\Program Files\IrfanView\i_view32.exe") & " " & AddQuotes(varInputPath & "\" & varFileName) & " /print /silent"
                WSHShell.Run CMDRun, 2, true
                'Move the file
                Set aFile = objFSO.GetFile(varInputPath & "\" & varFileName)
                aFile.Move varOutputPath & "\" & varFileName
        End if
'Get rid of any IrfanView processes
CMDRun2 = AddQuotes("C:\Program Files\IrfanView\i_view32.exe /killmesoftly /silent")
WSHShell.Run CMDRun2, 2, true
Function AddQuotes(strInput)
        AddQuotes = Chr(34) & strInput & Chr(34)
End Function

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.