I have a slightly odd requirement in that I need to modify, under certain 
circumstances, the save path used for an NSDocument based application.  The 
reason for this is that I may, depending on the format chosen by the user, need 
to unpack the data into multiple files.  Under this circumstance, I want to 
create a folder at the location specified by the user, with the name of the 
source file (less the extension) as the folder name, and then I'll unpack the 
source file into this directory.

I thought that this would be nice and simple - but it seems that the URL used 
when saving is an intermediate URL.  My file doesn't get created at the final 
destination location (and, because it doesn't, I can't easily modify the path). 
 What I planned to do is this:

- (BOOL)writeToURL:(NSURL *)url ofType:(NSString *)inTypeName error:(NSError 
**)outError

//Bunch of code and then...// 

        NSString *filename = [[url absoluteString] lastPathComponent];
        NSString *directory = [[[url absoluteString] 
stringByDeletingLastPathComponent] 
                               stringByAppendingFormat:@"/%@",[filename 
stringByDeletingPathExtension]];
        
        NSFileManager *fileManager= [NSFileManager defaultManager];        
        
        NSError *error = nil;
        if(![fileManager createDirectoryAtPath:directory
                   withIntermediateDirectories:YES
                                    attributes:nil
                                         error:&error])
        {
            success = false;
        }
        else
        {            
            url = [NSURL fileURLWithPath:[NSString 
stringWithFormat:@"%@/%@",directory,filename]];
        }

When I check url I get something like 
file://localhost/private/var/folders/6w/6dmwl9c938g4m94jm7s_8ml80000gn/T/TemporaryItems/(A%20Document%20Being%20Saved%20By%20Extractor)/Christmas.ext

Does anyone have the key to what I should be doing - because I'm clearly 
approaching this from the wrong angle! 
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to