The Artima Developer Community
Sponsored Link

Python Buzz Forum
Watch folder for change

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Martin Skou

Posts: 20
Nickname: martinskou
Registered: Jul, 2007

Martin Skou is a developer in Infoserv
Watch folder for change Posted: Sep 21, 2009 1:48 PM
Reply to this message Reply

This post originated from an RSS feed registered with Python Buzz by Martin Skou.
Original Post: Watch folder for change
Feed Title: Python Fanatic
Feed URL: http://blog.1x.dk/feeds/posts/default
Feed Description: On Python web development.
Latest Python Buzz Posts
Latest Python Buzz Posts by Martin Skou
Latest Posts From Python Fanatic

Advertisement

import os
import sys
import time

import win32file
import win32event
import win32con

ACTIONS = {
1 : "Created",
2 : "Deleted",
3 : "Updated",
4 : "Renamed from something",
5 : "Renamed to something"
}
FILE_LIST_DIRECTORY = 0x0001

path_to_watch = u"d:\\test"
path_to_watch = os.path.abspath (path_to_watch)

print "Watching %s at %s" % (path_to_watch, time.asctime ())

FILE_LIST_DIRECTORY = 0x0001
hdir = win32file.CreateFile (path_to_watch,
FILE_LIST_DIRECTORY, win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE,
None, win32con.OPEN_EXISTING, win32con.FILE_FLAG_BACKUP_SEMANTICS, None)


while 1:

results = win32file.ReadDirectoryChangesW (
hdir, 1024, True,
win32con.FILE_NOTIFY_CHANGE_FILE_NAME |
win32con.FILE_NOTIFY_CHANGE_DIR_NAME |
win32con.FILE_NOTIFY_CHANGE_ATTRIBUTES |
win32con.FILE_NOTIFY_CHANGE_SIZE |
win32con.FILE_NOTIFY_CHANGE_LAST_WRITE |
win32con.FILE_NOTIFY_CHANGE_SECURITY,
None, None
)
for action, file in results:
full_filename = os.path.join (path_to_watch, file)
print full_filename, ACTIONS.get (action, "Unknown")

Read: Watch folder for change

Topic: Watch folder for change Previous Topic   Next Topic Topic: Message: Re: [rest-discuss] REST-*

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use