Advertisement
Guest User

batch_print_tool

a guest
Aug 2nd, 2013
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1.  
  2. import win32print
  3. import win32api
  4. from os.path import isfile, join
  5. import glob
  6. import os
  7. import time
  8.  
  9. source_path = "c:\\temp\\source\\"
  10.  
  11. def main():
  12.     printer_name = win32print.GetDefaultPrinter()
  13.     while True:
  14.         file_queue = [f for f in glob.glob("%s\\*.txt" % source_path) if isfile(f)]
  15.         if len(file_queue) > 0:
  16.             for i in file_queue:
  17.                 hinstance = print_file(i, printer_name)
  18.                 print hinstance
  19.                 raw_input("press enter")
  20.                 if hinstance > 32:
  21.                     delete_file(i)
  22.                 print "Filename: %r has printed" % i
  23.                 print
  24.                 time.sleep(.25)
  25.                 print                
  26.         else:
  27.             print "No files to print. Will retry in 15 seconds"
  28.         time.sleep(15)
  29.    
  30.  
  31. def print_file(pfile, printer):
  32.     hinstance = win32api.ShellExecute(
  33.         0,
  34.         "print",
  35.         '%s' % pfile,
  36.         '/d:"%s"' % printer,
  37.         ".",
  38.         0
  39.         )
  40.     time.sleep(.25)
  41.     return hinstance
  42.  
  43.    
  44. def delete_file(f):
  45.     os.remove(f)
  46.     print f, "was deleted!"
  47.  
  48. def alert(email):
  49.     pass
  50.  
  51. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement