[python-win32] ReadDirectoryChangesW Bug...

Jos Yule jos@trapeze.com
Tue, 21 Jan 2003 15:36:51 -0500


Ok, so it returns an array of tuples. [(action,filename)]. Great. However, the filename has a bunch of 'extra' unicode bytes tacked on to the end of it. I've tried many different values in the buffer_size param to see if i could reduce the amount of garbage bytes, but it seems to have/make no difference. 

Looking at win32file.i line 1190 where the PyObject_FromFILE_NOTIFY_INFORMATION is defined (just above PyReadDirectoryChangesW) offered me no hints, but i think that there must be some misunderstanding between &bytes_returned/nbytes, which is why there are garbage bytes being malloc'ed onto the end of the fName.FileName object.

Or it could just be me not understanding how to use Unicode strings in python...

Thanks again,
jos


ps. the only other weird thing i've found is when using win32con.FILE_NOTIFY_CHANGE_LAST_WRITE, when i save from some program's it will notify me twice, with others only once. I'm sure it has to do with the different write/change/created date attributes... but its not an issue of this function working incorrectly, just me not understanding what the different apps are doing.

pps. Here is a trace of what it looks like (the file name is 'test.txt'):
<output>
D:\Projects\python\testing>script2.py
Watching D:\Projects\python\testing at Tue Jan 2
[(3, u'test.txt\u5c30t\u6290t\u7560v\u79b0v')]
[(3, u'test.txt\u5c30t\u6290t\u7560v\u79b0v')]
</output>

from the code:
<code>
import os
import sys
import time

import win32file
import win32con

try: path_to_watch = sys.argv[1] or "."
except: path_to_watch = "."
path_to_watch = os.path.abspath (path_to_watch)

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

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

while 1:
    time.sleep(0.1)
    result = win32file.ReadDirectoryChangesW(
        hDir,
        256,
        0,
        win32con.FILE_NOTIFY_CHANGE_LAST_WRITE,
        None,
        None
    )
    print result
</code>
-- 


Jos Yule
EWACT (employee without a cool title)

Trapeze
2 Berkeley St. Suite 305
Toronto, On, CANADA
M5A 4J5

t: 416 601 1999 x227
f: 416 601 1997
e: mailto:jos@trapeze.com
w: http://www.trapeze.com