[Pythonmac-SIG] Creating resource files

Michael Hudson mwh@python.net
Tue, 18 Mar 2003 14:45:12 +0000


So, I have a path, a creator code and a type code.  I want to create a
file with a resource fork.  This is the code I have now:

                # this cannot possibly be the easiest way of doing this.
                dir = os.path.dirname(path)
                if not dir:
                    dir = os.curdir
                volID = File.FSSpec(dir).as_tuple()[0]
                dirRef = File.FSRef(dir)
                ci = dirRef.FSGetCatalogInfo(Files.kFSCatInfoNodeID)
                dirID = ci[0].nodeID
                newSpec = File.FSSpec((volID, dirID,
                                       os.path.basename(path)))
                newSpec.FSpCreate(CREATOR, TYPE, 0)
                Res.FSpCreateResFile(path, CREATOR, TYPE, 0)

Surely there's an easier way than this?  The main problem is getting a
FSSpec to the not yet existing file and the main problem with that
seems to be getting the dirID of the parent.  My faded Mac knowledge
suggests PBGetCatInfo for this, but that doesn't seem to be
accessible...

(I guess there's a more modern FSRef-y way of doing the same thing,
but I really need the type and creator setting, and I couldn't see how
to get FSCreateFileUnicode to do that).

TIA!

Cheers,
M.

PS: anyone here play Ambrosia Software's Escape Velocity Nova?  I may
    have a need for beta testers soon...

-- 
  I never disputed the Perl hacking skill of the Slashdot creators. 
  My objections are to the editors' taste, the site's ugly visual 
  design, and the Slashdot community's raging stupidity.
     -- http://www.cs.washington.edu/homes/klee/misc/slashdot.html#faq