This is on the Mac:
If I have two filenames /foo/foo and /foo/FOO they may refer to the same file or the may be different files depending on the file system. How do I figure out if they are both pointing to the same file? And if they are, how do I get the correct representation of the filename?
My problem is caused by links. A link might point to /foo/FOO but the actual directory is named /foo/foo.
Is there any function that will follow a link and give me the the full path of the linked file? [NSFileManager pathContentOfSymbolicLinkAtPath] gives relative paths that might be in the incorrect case.
Ultimately what I’m try to do is cache info for files. But if I have two different paths for the same file, my cache can get out of sync.
Thanks
There’s really a couple of different parts to your question. By my reading, you want:
There’s a third issue that gets mixed in, as well, having to do with Display Names, because in OS X a file can localize its name and appear differently for different locales. So let’s add
We can solve 1 with the FSRef trick pointed out by @boaz-stuller. Or here’s some code that does it using higher-level Cocoa calls, which saves us a little bit of memory juggling (since we can let the
NSAutoreleasePooldo it for us):But to solve 2, we’ve got to use FSRefs to find out the canonical casing of the file:
That’s not bad at all, but we’re still happy when we can solve 3 with Cocoa methods:
Finally, we can add a bit of driver code and tie this all together into a CoreFoundation command line tool (I had to add the AppKit framework to get this to compile).
Now, we can put it all together and run it: