Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 92571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:12:28+00:00 2026-05-10T23:12:28+00:00

This is on the Mac: If I have two filenames /foo/foo and /foo/FOO they

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T23:12:28+00:00Added an answer on May 10, 2026 at 11:12 pm

    There’s really a couple of different parts to your question. By my reading, you want:

    1 a way to tell if two different paths are the same on-disk file

    2 a canonical name for the file on disk, with the proper casing

    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

    3 a way to get the display name, because we might want to cache things depending on how the user sees the file system, not how the file system appears in the terminal.

    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 NSAutoreleasePool do it for us):

    long getInode(NSString* path) {     NSFileManager* fm = [NSFileManager defaultManager];     NSError* error;     NSDictionary* info = [fm attributesOfItemAtPath:path error:&error];     NSNumber* inode = [info objectForKey:NSFileSystemFileNumber];     return [inode longValue]; } 

    But to solve 2, we’ve got to use FSRefs to find out the canonical casing of the file:

    NSString* getActualPath(NSString* path) {     FSRef ref;     OSStatus sts;     UInt8* actualPath;          //first get an FSRef for the path     sts = FSPathMakeRef((const UInt8 *)[path UTF8String], &ref, NULL);     if (sts) return [NSString stringWithFormat:@"Error #%d making ref.", sts];          //then get a path from the FSRef     actualPath = malloc(sizeof(UInt8)*MAX_PATH_LENGTH);     sts = FSRefMakePath(&ref, actualPath, MAX_PATH_LENGTH);     if (sts) return [NSString stringWithFormat:@"Error #%d making path.", sts];          return [NSString stringWithUTF8String:(const char*)actualPath]; } 

    That’s not bad at all, but we’re still happy when we can solve 3 with Cocoa methods:

    NSString* getDisplayPath(NSString* path) {     NSFileManager* fm = [NSFileManager defaultManager];     NSString* mine = [fm displayNameAtPath:path];     NSString* parentPath = [path stringByDeletingLastPathComponent];     NSString* parents = [@"/" isEqualToString:parentPath]         ? @""         : getDisplayPath(parentPath);     return [NSString stringWithFormat:@"%@/%@", parents, mine]; } 

    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).

    NSString* fileInfoString(NSString* path) {     long inode = getInode(path);     return [NSString stringWithFormat:         @"\t%@  [inode #%d]\n\t\tis actually %@\n\t\tand displays as %@",         path,         inode,         getActualPath(path),         getDisplayPath(path)]; }  int main (int argc, const char * argv[]) {     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];      if (argc < 2) {         NSLog(@"Usage: %s <path1> [<path2>]", argv[0]);         return -1;     }      NSString* path1 = [NSString stringWithCString:argv[1]];     NSString* path2 = argc > 2         ? [NSString stringWithCString:argv[1]]         : [path1 uppercaseString];          long inode1 = getInode(path1);     long inode2 = getInode(path2);          NSString* prefix = [NSString stringWithFormat:         @"Comparing Files:\n%@\n%@",          fileInfoString(path1),          fileInfoString(path2)];          int retval = 0;     if (inode1 == inode2) {         NSLog(@"%@\nSame file.", prefix);     } else {         NSLog(@"%@\nDifferent files.", prefix);         retval = 1;     }          [pool drain];     return retval; } 

    Now, we can put it all together and run it:

      $ checkpath /users/tal  2008-12-15 23:59:10.605 checkpath[22375:10b] Comparing Files:     /users/tal  [inode #1061692]         is actually /Users/tal         and displays as /Users/tal     /USERS/TAL  [inode #1061692]         is actually /Users/tal         and displays as /Users/tal  Same file. 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 64k
  • Answers 64k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You should take a look at Redmine (http://www.redmine.org/). It has… May 11, 2026 at 10:49 am
  • added an answer I'm not sure if sqllite allows for variables, but this… May 11, 2026 at 10:49 am
  • added an answer The Answer The compiler was, in fact, calculating an incorrect… May 11, 2026 at 10:49 am

Related Questions

This is on the Mac: If I have two filenames /foo/foo and /foo/FOO they
I know this is probably on the Internet somewhere but I can't find the
This is the constraint I have on the Customers table. ALTER TABLE Customers ADD
This is a specific variation on the can't connect problem. In my case, I've
This is re-posted from something I posted on the DDD Yahoo! group. All things
This is a question you can read everywhere on the web with various answers:
On the page http://msdn.microsoft.com/en-us/library/bb202066.aspx If references something called POLL Driver V2 however this is
I'm starting a new personal project on the side, so this is the first
This is a follow-on question to the How do you use ssh in a
This web page http://www.w3schools.com/ASP/prop_sessionid.asp states that a session ID is generated on the ServerSide.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.