Skip navigation.
 
mlcreateDirectoryAtPath anomaly between system versions?
FROM : Antonio Nunes
DATE : Wed Jul 05 11:47:37 2006

Hi,

Is anybody aware of a change/bug-fix somewhere between 10.4.3 and 
10.4.7 where creating a directory in applicationWillFinishLaunching 
works in 10.4.7 but not in 10.4.3?

On my PowerBook running 10.4.7 everything works fine, but on my iBook 
running 10.4.3 the directory is not created, even though to the code 
it looks like it does. Surprisingly [fileManager 
createDirectoryAtPath:myAppDirectoryPath attributes:nil] returns 
successfully, so my code doesn't see the error until later when it 
looks for the app's directory in the application support folder and 
finds it is not there.

On 10.4.3 I can successfully create the directory a moment later in 
applicationDidFinishLaunching. But I really need it before that. The 
folowing code is called from applicationWillFinishLaunching:

- (NSString *)
createMyAppApplicationSupportDirectoryIfNeededWithDomainMask:(int)
domainMask
{
   BOOL             isDir, exists, success = NO;
   NSFileManager    *fileManager = [NSFileManager defaultManager];
   NSString        *myAppDirectoryPath = nil;

   NSArray    *paths = NSSearchPathForDirectoriesInDomains
(NSApplicationSupportDirectory, domainMask, YES);
   
   if ([paths count] > 0)  {
       myAppDirectoryPath = [[paths objectAtIndex:0] 
stringByAppendingPathComponent:@"MyApp"];
       exists = [fileManager fileExistsAtPath:myAppDirectoryPath 
isDirectory:&isDir];
       if (!isDir) {
           // There is no MyApp directory so create it
           success = [fileManager createDirectoryAtPath:myAppDirectoryPath 
attributes:nil];
           if (!success) {
               myAppDirectoryPath = nil;
               NSRunAlertPanel(@"MyApp",
                               NSLocalizedString(@"Could not create MyApp directory", 
@"Could not create the \"MyApp\" directory in %@"),
                               NSLocalizedString(@"OK", @"OK"),
                               NULL,  NULL,
                               [myAppDirectoryPath stringByDeletingLastPathComponent]);
           }
       } // if (!isDir)
   } else {
       NSRunAlertPanel(@"MyApp",
                       NSLocalizedString(@"AppSupportDirectoryMissing", @"The 
Application Support folder is missing."),
                       NSLocalizedString(@"OK", @"OK"),
                       NULL,  NULL);                        
   }

   return myAppDirectoryPath;
}

Thanks,
António

-----------------------------------------------------------
What you have inside you expresses itself through both your
choice of words and the level of energy you assign to them.
The more healed, whole and connected you feel inside,
the more healing your words will be.

--Rita Goswami
-----------------------------------------------------------

Related mailsAuthorDate
mlcreateDirectoryAtPath anomaly between system versions? Antonio Nunes Jul 5, 11:47
mlRe: [SOLVED] createDirectoryAtPath anomaly between system versions? Antonio Nunes Jul 7, 12:35
mlRe: [SOLVED] createDirectoryAtPath anomaly between system versions? Nir Soffer Jul 7, 14:28
mlRe: [SOLVED] createDirectoryAtPath anomaly between system versions? Antonio Nunes Jul 7, 16:01
mlRe: Re: [SOLVED] createDirectoryAtPath anomaly between system versions? Michael Ash Jul 7, 19:28