-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_gen.py
executable file
·55 lines (47 loc) · 1.87 KB
/
file_gen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Utility to check for any new file creation in path specified
# by path & display some content from them
# author Abhiroop Dabral
# v 1.0
import os
import re
import datetime
import win32file
import win32event
import win32con
import string
path= r"C:\Users\dZONE\Desktop\py"
# path to watch for
change_handle = win32file.FindFirstChangeNotification (path,0,win32con.FILE_NOTIFY_CHANGE_FILE_NAME)
try:
old_path_contents = dict ([(f, None) for f in os.listdir (path)])
while 1:
result = win32event.WaitForSingleObject (change_handle, 500)
if result == win32con.WAIT_OBJECT_0:
new_path_contents = dict ([(f, None) for f in os.listdir (path)])
added = [f for f in new_path_contents if not f in old_path_contents]
#deleted = [f for f in old_path_contents if not f in new_path_contents]
#if added: print "Added: ", ", ".join (added)
#if deleted: print "Deleted: ", ", ".join (deleted)
# My open
for item in added:
#print item
match_hdr = re.search(r'\.hdr$',item,re.M)
if match_hdr:
#print "HDR FOUND"
fullfilename = os.path.join(path, item)
hdr_file=open(fullfilename,'r')
#print '__________________________________\n'
print "Job received on server @:", datetime.datetime.now(), '\n'
for line in hdr_file:
if 'ENTITY_MODE' in line: print line,
if 'ENTITY_NAME' in line: print line,
if 'JOB_NAME' in line: print line,
if 'PRINTER_NAME' in line: print line,
if 'JOB_TOTAL_PAGES' in line: print line,
if 'JOB_NB_COPY' in line: print line,
print '_______________________________________\n'
hdr_file.close()
old_path_contents = new_path_contents
win32file.FindNextChangeNotification (change_handle)
finally:
win32file.FindCloseChangeNotification (change_handle)