473,544 Members | 1,822 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

monitoring folder in python

Is it possible to monitor a folder in the python?My question is if I
put any file in it that particular folder my script should monitor the
folder and read the file name.If so what function can I use?

Thanx in advance

Jul 18 '05 #1
2 7320
Raghul wrote:
Is it possible to monitor a folder in the python?My question is if I
put any file in it that particular folder my script should monitor the
folder and read the file name.If so what function can I use?

Thanx in advance


If you do not want to poll (check for changes yourself regularly),
here are some pointers:

In Windows:

With the win32 extensions, it's quite simple:

http://tgolden.sc.sabren.com/python/...r_changes.html

In Linux:

http://www.edoceo.com/creo/inotify/

http://www.student.lu.se/~nbi98oli/dnotify.html

http://www.lambda-computing.com/projects/dnotify/

Don't know of any Python extensions for the above, so you might
have to write your own if you want to use them from Python. Also,
you probably need to reconfigure and compile a new kernel. Have
tested inotify myself and it seems to work, you also get the filename
with the event. Only problem is it don't support monitoring a directory
recursive (subdirectories ) like in Windows with ReadDirectoryCh angesW.

Jul 18 '05 #2
A straw-man solution in Python that monitors a directory for changes
(Linux only):

#!/usr/bin/env python2

import sys
import os

if sys.platform not in ("linux2",):
sys.exit("%s only runs on Linux" % os.path.basenam e(sys.argv[0]))

# TODO: we should check that kernel version >= 2.4.19
# e.g. with 'uname -r'

import fcntl
import signal

TESTDIRECTORY = "."

def notify(director y, handler):
fd = os.open(directo ry, os.O_RDONLY)
fcntl.fcntl(fd, fcntl.F_NOTIFY,
fcntl.DN_ACCESS |fcntl.DN_MODIF Y|fcntl.DN_CREA TE)
signal.signal(s ignal.SIGIO, handler)

def handler(signum, frame):
print "Something happened; signal =", signum

if __name__ == "__main__":
notify(TESTDIRE CTORY, handler)
try:
signal.pause() # sleep until signal received
except KeyboardInterru pt:
pass

With Python 2.4 one could bind e.g. to signal.SIGRTMIN instead of the
default SIGIO and get additional info, as suggested by the C example in
Documentation/dnotify.txt (look in the Linux src tree). But then I am
note sure you can access a siginfo structure directly from Python. With
the example above, one would probably write the handler so that it
rescans the directory when called to detect what actually changed.

Davide

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4132
by: Ron Vecchi | last post by:
Hi all, Can someone point me in the direction on this one, resources or examples. I am writing a Windows Service to monitor a folder. When I file is modified within the folder or any subfolders it should write the name of the file to a xml file. Then at a specifed time all the files in the xml quene will be backed up on a network share. ...
0
2079
by: Jeff Reed | last post by:
I am experiencing the the problem outlined the below. Unfortunately, I am using WinXP and I not sure if I can apply the solution due to lack of security control Any feed back would be apreciated http://support.microsoft.com/default.aspx?scid=kb;EN-US;31795 FIX: "Failed to Start Monitoring Directory Changes" Error Message When You Browse...
7
13367
by: Mark | last post by:
Hello, I have researched and tried every thing I have found on the web, in groups and MS KB articles. Here is what I have. I have a Windows 2000 Domain Controller all service packs and every thing else from windows update. ..NET 1.0 and 1.1 installed on the server. Actually .NET was installed before the server was made a DC.
4
7349
by: kimpton | last post by:
Hi, My App running on my local machine is trying to access apsx and ascx pages via a virtual directory (see earlier post) that points to a share on a different machine. I can now access .aspx and run .aspx pages ok. However I've added a <@ register tag to a local page that references a .ascx page on the remote share (via the virtual...
2
4120
by: Greg Allen | last post by:
I know this has been discussed before, and have found some documentation about it on the web. But nothing has fixed my problem. I am running the 1.1 .NET framework, SP1. I have a web application that I would like to place on a remote shared drive on a different computer. I had problems with that, so I simplified it so that I am trying...
5
483
by: Joe | last post by:
I'm getting the following error when trying to call a page on a secure server. I'm not doing any impersonations or file access of any kind. The page is using PayPal and I'm wondering if PayPal has something to do with this. We had to register an api certificate on the server using WinHttpCertCfg. Maybe this is doing something? Access denied...
1
4339
by: amit.vasu | last post by:
Hi I have created a web serivces using .net framework 2.0. When I try to execute the web service I get the following error. Failed to start monitoring changes to 'e:\Default Web Site' because access is denied. I am running windows 2003 sp1. Network Service account do have full permission on application folder and sub folder.
1
2414
by: William Connery | last post by:
Hi, I have a small python program with e-mail capabilities that I have pieced together from code snippets found on the internet. The program uses the smtplib module to successfully send an e-mail with an attachment. I want to give users an indication of the percentage of the e-mail that has already been sent so as to avoid frustration...
5
1995
by: rohit | last post by:
hi, i am designing a desktop search engine using python. i am having a query , is there a package available that contains functions for retrieving the files being edited , created,deleted in the file system. thanks
0
7431
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7617
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7387
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5305
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4924
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3424
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3415
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1848
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
674
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.