Created
May 26, 2016 17:10
-
-
Save vinovator/eee602e7c659c342ba455c207c6348e4 to your computer and use it in GitHub Desktop.
Print all documents from set of folders using default printer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# print_docs.py | |
# Python 2.7.6 | |
""" | |
Print all documents from set of folders using default printer | |
""" | |
import os | |
import win32print | |
import win32api | |
base_folder = "C:\some_folder" | |
print_folders = ["Folder1", "Folder2"] | |
common_folder = "Common" | |
no_of_prints = 3 | |
def print_files_from_folder(dir): | |
""" | |
Given a folder name print all the files within it | |
""" | |
for path, folders, files in os.walk(os.path.join(base_folder + "/" + dir)): | |
for file in files: | |
print("Printing {}".format(base_folder + "/" + dir + "/" + file)) | |
# Print each file | |
try: | |
win32api.ShellExecute(0, "print", | |
(base_folder + "/" + dir + "/" + file), | |
None, ".", 0) | |
except Exception as e: | |
print e | |
if __name__ == "__main__": | |
""" Starting block of script """ | |
printer_name = win32print.GetDefaultPrinter() | |
print("printing from {}".format(printer_name)) | |
printer = win32print.OpenPrinter(printer_name) | |
# Print all files from the set of folders | |
for folder in print_folders: | |
print_files_from_folder(folder) | |
# Print 3 copies of taxi bills | |
for count in range(no_of_prints): | |
print_files_from_folder(common_folder) | |
# To check print status | |
# phandle = win32print.OpenPrinter(printer_name) | |
# print_jobs = win32print.EnumJobs(phandle, 0, -1, 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment