简体   繁体   中英

Cocoa contentsOfDirectoryAtPath: method failing with error for certain users - Mac OS X

Here's a snippet of the code:

// Get into the data folder of it
keychainPath = [keychainPath stringByAppendingPathComponent:@"data/default"];

DLog(@"Keychain data path: %@", keychainPath);

// Define Filemanager
NSFileManager *fm = [NSFileManager defaultManager];

// Catch any errors
NSError *dataError = nil;

// get all the files in the directory
NSArray *dataFiles = [fm contentsOfDirectoryAtPath:keychainPath error:&dataError];

if(!dataFiles)
 NSLog(@"Error: %@",dataError);

Now this works perfectly fine for most people, but a few have reported problems, with the 'dataError' object giving:

  Error: Error
Domain=NSCocoaErrorDomain Code=260 UserInfo=0x14d1fa10 "The folder
“default” doesn’t exist." Underlying Error=(Error
Domain=NSOSStatusErrorDomain Code=-43 "The operation couldn’t be
completed. (OSStatus error -43.)" (File not found))

The people having this problem have said that the file / folder 'default' DOES exist exactly where is should be, so I have no idea why this isn't working.

Any help would be appreciated!

Thanks Peter, the keychainPath was just some string like '~/Library/etc.etc.'

To answer my own question:

It turns out the problem was because some people's Mac OS X installations were getting confused about the tilde (~)

Using the method

[keychainPath stringByExpandingTildeInPath];

Once this was done, the problem was solved.

I guess the reason for the problem was for people with multiple user accounts, which I didn't have.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM