(original) (raw)

import Carbon.File import os.path import string def ResolveFinderAliases(path): """Returns a version of the supplied path with all Finder aliases converted to their real locations """ if path is "": return path # We need to keep testing a full path until all the aliases have # been removed finished = 0 while not finished: comps = string.split(path,'/') for i,c in enumerate(comps): if c == '': comps[i] = '/' result = "" for i, comp in enumerate(comps): # Add the next component of the path result = os.path.join(result,comp) # Check for an alias fss = Carbon.File.FSSpec(result) fss, isFolder, aliased = Carbon.File.ResolveAliasFile(fss,0) if aliased: # Get where the alias points to fsr = Carbon.File.FSRef(fss) path = fsr.FSRefMakePath() for j in range(i+1,len(comps)): path = os.path.join(path,comps[j]) # Start the process again - the target of this alias # might have an alias further up the path. break elif i == len(comps)-1: # Reached the last component without finding # an alias - finished. finished = 1 return result