Importing modules through directory shortcuts on Windows

Roger Upole rupole at hotmail.com
Thu Apr 27 15:01:08 EDT 2006


Warning: Ugly code ahead

import win32con, winioctlcon, winnt
import win32file, win32api
import os, struct

temp_dir=win32api.GetTempPath()
temp1=win32api.GetTempFileName(temp_dir,'rpp')[0]
win32file.DeleteFile(temp1)
os.mkdir(temp1)
temp2=win32api.GetTempFileName(temp_dir,'rpp')[0]
win32file.DeleteFile(temp2)
os.mkdir(temp2)
print temp1, temp2

temp2_abs=u'\\??\\'+temp2
printname=unicode(os.path.split(temp2)[1])
temp2buf=buffer(temp2_abs)[:]
printnamebuf=buffer(printname)[:]

## ???? need figure out how print name should be placed in the buffer, think it needs to follow an
## explicit double null terminator after the target string
printnamebuf=''

databufsize=len(temp2buf)+len(printnamebuf) ## final size includes everything past the reparse tag
fmt="LHHHHHH%ss" %(databufsize+4)
buf=struct.pack(fmt, winnt.IO_REPARSE_TAG_MOUNT_POINT,
                databufsize+12, 0, 0, len(temp2buf), len(temp2buf)+2,
                len(printnamebuf), temp2buf+printnamebuf+'\0\0\0\0')
bufsize=struct.calcsize(fmt)

h = win32file.CreateFile(temp1, win32con.GENERIC_READ|win32con.GENERIC_WRITE,
        win32con.FILE_SHARE_READ|win32con.FILE_SHARE_WRITE|win32con.FILE_SHARE_DELETE, None,
        win32con.OPEN_EXISTING, win32file.FILE_FLAG_BACKUP_SEMANTICS|win32file.FILE_FLAG_OPEN_REPARSE_POINT, 0)

## old_buf=win32file.DeviceIoControl(h, winioctlcon.FSCTL_GET_REPARSE_POINT,'',winnt.MAXIMUM_REPARSE_DATA_BUFFER_SIZE,None)
win32file.DeviceIoControl(h, winioctlcon.FSCTL_SET_REPARSE_POINT, buf, 0, None)

## create a subdir in redirected dir and make sure it shows up in target dir
os.mkdir(os.path.join(temp1,'new_dir'))
assert os.path.isdir(os.path.join(temp2,'new_dir'))
h.Close()

        Roger






"Tim Golden" <tim.golden at viacom-outdoor.co.uk> wrote in message news:mailman.5039.1146126500.27775.python-list at python.org...
[Roger Upole]

| You can use win32file.DeviceIoControl to link directories.
| I can post some code to do so if anyone's interested.

I'd certainly be interested...

Thanks
TJG

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________






More information about the Python-list mailing list