[Pythonmac-SIG] alias question
Joseph J. Strout
joe@strout.net
Fri, 26 Feb 1999 12:45:10 -0800
At 11:58 AM -0800 02-26-99, Chris Walker wrote:
>question is this: is there a way to determine whether or not a file is an
>alias
>such that if the alias points to a network volume, the user won't be prompted.
Yep. I don't use os.path.walk() -- mainly because I didn't know about it
-- but I do the same thing with a FileCrawler class, which lets you define
behavior to take for docs, folders, doc aliases, and folder aliases:
import mac
import macfs
from MACFS import *
class FileCrawler:
def handleAlias(self, path):
print "Document alias:", path
def handleFolderAlias(self, path):
print "Folder alias:", path
def handleDocument(self, path, typecode):
print typecode, "Document:", path
def handleFolder(self, path):
print "Folder:", path
self.crawl(path)
def crawl(self, path):
files = mac.listdir(path)
for fname in files:
if path[-1] == ':': fpath = path + fname
else: fpath = path + ':' + fname
spec = macfs.FSSpec(fpath)
try:
info = spec.GetFInfo()
except:
# if GetFInfo fails, it must be a folder!
info = macfs.FInfo()
info.Type = 'fldr'
if info.Flags & kIsAlias:
if info.Type == 'fdrp':
self.handleFolderAlias(fpath)
else:
self.handleAlias(fpath)
elif info.Type == 'fldr':
self.handleFolder(fpath)
else:
self.handleDocument(fpath, info.Type)
>---
>Chris Walker
>Pixar Animation Studios
Cool -- are you guys using MacPython at Pixar?
Cheers,
-- Joe
,------------------------------------------------------------------.
| Joseph J. Strout Biocomputing -- The Salk Institute |
| joe@strout.net http://www.strout.net |
`------------------------------------------------------------------'