| Home     My Faqts     Contributors     About     Help

FAQTS : Computers : Programming : Languages : Python : Snippets : Stream Manipulation : Files

My Recent Searches

Knowledge Base
Python Knowledge Base
Files Folder

Entry | Add Entry Alert - Edit this Entry

Did You Find This Entry Useful?

4 of 4 people (100%) answered Yes

Scanning folders for new files

Jul 5th, 2000 13:03
Nathan Wallace, Fiona Czuczman
Hans Nowak, Snippet 386, Darrell

"""
Packages: operating_systems.windows
"""

"""
> what is the best and fastest way to scan a whole list of folders
> to see if something is added or not. Please note that this should
> also work for more than 1000 folders (and it shouldn't slow down
> the system too much).

If your talking about NT then give this a try.
http://www.dorb.com/darrell/win32WorkSvr/makeThumbsDG.py
"""

import win32file, win32event, os, winnt, traceback

def main():
"""
Use events to avoid polling.
A sleep is used to give most files a chance to finish
being writen. Sort of a hack and might not be needed.
The notification event LAST_WRITE seems to trigger
at the start and end of writing. So a single file
will trigger this twice.
"""
hnd=win32file.FindFirstChangeNotification\
(os.path.abspath('.')+os.sep+'incoming'\
,0, winnt.FILE_NOTIFY_CHANGE_LAST_WRITE )

while 1:
int = win32event.WaitForSingleObject( hnd, -1)
# Try to give the file time to finish writing
time.sleep(2)
print 'run'
try:
passed, failed, skipped = makeThumbNails()
except:
if '-d' in sys.argv:
traceback.print_exc()
raise ThumbNailException
win32file.FindNextChangeNotification(hnd)

main()

© 1999-2000 Synop Software