Re: How can I standardize a path name? (Cocoa solution wanted)
Re: How can I standardize a path name? (Cocoa solution wanted)
- Subject: Re: How can I standardize a path name? (Cocoa solution wanted)
- From: Doug Simons <email@hidden>
- Date: Fri, 25 Jan 2002 10:28:03 -0700
On Thursday, January 24, 2002, at 06:48 PM, Rainer Brockerhoff
<email@hidden> wrote:
I'm trying to find a way to get a full standardized path name for a
file. The difficulty is related to HFS+ and Apple's file extension
hiding mechanism.
...
HFS+ will allow me to access the file using either the upper- or
lower-case version of the name, but I need a way to know how it is
actually stored on the disk, so I don't open it twice (and also so that
I can present the name to the user the way it appears in the file
system).
...
So, does anyone know a good, straightforward method of standardizing a
file path that will distinguish between "test", "TEST", "test.st", and
"TEST.st" if all of those files exist, but will yield the form of the
name as stored in the file system if only one case exists? To qualify
as a good answer, it must work on any file system supported by OS X and
ideally not require reading through the entire directory!
AFAIK, the only absolutely fool-proof method to check that two paths
point at the same file - and one that also covers symbolic links, and
uppercasing anywhere in the path name - is making a FSSpec for both and
comparing the FSSpecs with FSCompareFSRefs(). To make a FSRef for a
path, call FSPathMakeRef([pathName
fileSystemRepresentation],&newFSRef,NULL).
You may want to pre-store FSRefs instead of paths for files you have
opened, in your case.
Thanks for the suggestion, but I'd really like a Cocoa solution if
possible. It seems like there must be SOME way in Cocoa to get the
actual, case-specific name of a file, including its extension, given the
(possibly not case-specific, but sufficient to access the file) pathname.
Any other ideas?
Doug