Announcement

Collapse
No announcement yet.

Print files from folder

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Print files from folder

    Hi guys..

    I don't know if any of you guys have experienced this before, but what we need is a bit weird.

    i want to have a script to look into a folder, and then if there are any files in that folder, i want the script to print those documents...and then after they are printed, have them moved to another folder....

    so eg...i have a folder called "docs_to_print"......i dump 2 word docs in there,....the script runs every half an hour and prints them to the designated printer/s, and then after that, moves the files to the "docs_printed" folder.

    any suggestions will be appreciated.

    thanks.

  • #2
    Re: Print files from folder

    This will use the shell command to print the file using the default viewer for the file type. There's no way to control the printer that is used AFAIK. It uses the default printer.

    I used a copy then delete operation because move is too unreliable. Primarily because, if the file is in use it can't delete the file or retry. This way the file will be copied then removed when it's freed [not in use].

    Schedule a task to have it run at the time interval you mentioned in your post.

    Code:
    On Error Resume Next
    
    Const FilePath = "C:\Users\Andrew\Desktop\Test" 
    Const DestPath = "C:\Users\Andrew\Desktop\Test\Printed\"
    
    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.Namespace(FilePath) 
    Set colItems = objFolder.Items
      For i = 0 to colItems.Count - 1
        colItems.Item(i).InvokeVerbEx("Print")
        wscript.sleep(500)
        ManageFile(colItems.Item(i))
      Next
    
    Sub ManageFile(FileSpec)
    Dim fso, myFile, FullPath
    FullPath = FilePath & "\" & FileSpec
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set myFile = fso.GetFile(FullPath)
        
      MyFile.Copy DestPath, True
    
      While fso.FileExists(FullPath)
        MyFile.Delete
          If fso.FileExists(FullPath) Then  'If the file still exists
            wscript.sleep(2000) 'Wait 2 seconds before trying to delete again
          End If
      Wend
    End Sub
    Last edited by ahinson; 20th June 2007, 07:36.
    Andrew

    ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

    Comment


    • #3
      Re: Print files from folder

      Thanks very much. The copy function is just as good, as I can just schedule a purge of the "DestPath" folder every now and then. Thanks very much.


      Now, my next script I am thinking is for broadcast printing, eg, Printing one document to several printers at once.

      For example, Monday newsletter, I want to print it to printers eg north1, north2, south1, south2, west1, west2, east1, east2, central,

      can this be done with a vbs script or a batch file?

      thanks very much for your help.

      Comment


      • #4
        Re: Print files from folder

        Originally posted by dublin_101 View Post
        Thanks very much. The copy function is just as good, as I can just schedule a purge of the "DestPath" folder every now and then. Thanks very much.


        Now, my next script I am thinking is for broadcast printing, eg, Printing one document to several printers at once.

        For example, Monday newsletter, I want to print it to printers eg north1, north2, south1, south2, west1, west2, east1, east2, central,

        can this be done with a vbs script or a batch file?

        thanks very much for your help.
        No problem glad to have helped.

        A way to do this since the print option from the shell opens the default viewer for the file type and then prints it to your default printer. Knowing this you could in script before each job based on some condition change the default printer then print the document. Then once done change the default printer back.
        Andrew

        ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

        Comment

        Working...
        X