Dave Opstad wrote: > > Just wondering if there's anything in MacPython for converting HFS paths to > > POSIX and vice-versa, or is my memory playing tricks on me? If not, does > > anyone have some code they don't mind sharing? > >To clarify: are you asking for something that converts a string with colons >to one with slashes and back; or something that converts from a slashpath >into FSRefs or FSSpecs?
The former; e.g. 'Mac HD:Users:has:' to '/Users/has' and back. ... Larry Meyn wrote: >Jack helped me out awhile back in creating HFS paths. The archive is at >http://mail.python.org/pipermail/pythonmac-sig/2003-August/008527.html Thanks, I hadn't thought of that. (BTW, that code should really use FSRefs and FSGetCatalogInfo() as FSSpecs can't show long filenames.) For what I'm doing, it'd probably be better if it wasn't limited to existing filesystem locations though. ... Nicholas Riley wrote: >Keep in mind that HFS paths aren't unique, whereas POSIX paths are, so >you should be using FSRefs, CFURLs, POSIX paths or aliases for >canonical representations, cognizant of all the tradeoffs between >those formats. > >from Carbon.CoreFoundation import * I'm kinda leery of using MacPython's CF wrapper as it's a bit buggy in places. Still your example looks like it works ok - good suggestion, thanks. One bit I'm not sure about though - if I run this: u = toCF('A Non-mounted Drive:').CFURLCreateWithFileSystemPath(kCFURLHFSPathStyle, False) print u.CFURLCopyFileSystemPath(kCFURLPOSIXPathStyle).toPython() I get '/A Non-mounted Drive' whereas I was assuming it should be '/Volumes/A Non-mounted Drive' - is that correct? ... Anyway, might help to show what I'm actually working on: http://freespace.virgin.net/hamish.sanderson/macfile-0.1.0.tar.gz It's a simple Swiss-army-knife wrapper for the various filesystem-related types floating around MacPython, mostly cos I got sick of dealing directly with them in appscript all the time. The Alias class is quite straightforward; the File class tries to be clever by retaining the original object it was constructed with and deferring to that as much as possible when performing conversions, etc. I'm not sure how useful HFS path conversion options will really be; it seemed an idea to put it in for completeness' sake, but perhaps it's just overkill? I'd be very happy to take a second opinion on this, as well as any comments on the rest of the design and implementation folks might have (e.g. there may be some unsafe assumptions being made, subtle bugs and user gotchas, etc. that I've not accounted for). Many thanks, has _______________________________________________ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig