Newbie - is Windows folder 'watcher' possible?

djw dwelch at nospam.vcd.hp.com
Tue Oct 8 17:15:17 EDT 2002


dfinner at Kollsman.com wrote:
> 
> I have written a simple script that reads a Windows directory and, if files are
> present, logs the file names into a text file and makes a copy of the file(s)
> into another location.  All that works great (and thanks to the Yahoo thread
> 52317, O'Reilly Python Programming on Win32, and the help files for pointers).
> 
> What I'd like to do as an enhancement is to have Python watch a specified
> directory and every time a new file is dumped into the directory, do the log and
> copy operation.   The folder is used by a 'Distiller' program that converts
> various source files into PDFs and I want to monitor use of the directory.  The
> files are in the 'Watch' folder only as long as it takes to generate the PDF
> then deleted.  For this reason, the 'log and copy' program needs to be right on
> top of what's in the folder (i.e. I can't run it once every 5 minutes).
> 
> The question: is it possible?  I like to learn to fish so pointers to the
> correct modules or resources are appreciated more than actual code.
> 
> Watch folder is on a WinNT server.
> I'm running Python 2.2 on Win2000
> 
> My thanks for any help.  I think I'm going to like this language!
> 
> Doug
> 
> 
> 
I would check here for some pointers:

http://systeminternals.com/ntw2k/utilities.shtml

This website has programs written in C/C++, but I think full source is 
available. You will have to "translate" the Win32 API calls made in 
C/C++ to Python code using win32all.

However, according to the way that their utility "filemon" works, it 
looks like you need a VxD ( a low level system driver ) to make this 
happen. You could possibly hook into their VxD, or maybe there is 
another way to do this, I'm not sure.

--------------------------------------------------

How Filemon Works
For the Windows 9x driver, the heart of Filemon is in the virtual device 
driver, Filevxd.vxd. It is dynamically loaded, and in its initialization 
it installs a file system filter via the VxD service, 
IFSMGR_InstallFileSystemApiHook, to insert itself onto the call chain of 
all file system requests. On Windows NT the heart of Filemon is a file 
system driver that creates and attaches filter device objects to target 
file system device objects so that Filemon will see all IRPs and FastIO 
requests directed at drives.
When Filemon sees an open, create or close call, it updates an internal 
hash table that serves as the mapping between internal file handles and 
file path names. Whenever it sees calls that are handle based, it looks 
up the handle in the hash table to obtain the full name for display. If 
a handle-based access references a file opened before Filemon started, 
Filemon will fail to find the mapping in its hash table and will simply 
present the handle's value instead.

--------------------------------------------------

Don






More information about the Python-list mailing list