• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Modifying the save path in an NSDocument based application
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Modifying the save path in an NSDocument based application


  • Subject: Modifying the save path in an NSDocument based application
  • From: Pax <email@hidden>
  • Date: Tue, 17 Sep 2013 13:49:56 +0100

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 Document Being Saved By Extractor)/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 (email@hidden)

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:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Modifying the save path in an NSDocument based application
      • From: Steve Mills <email@hidden>
  • Prev by Date: Re: Progress for archiving/dearchiving
  • Next by Date: OS X 10.8.5 Can't detect FactTime Camera on new macbook air
  • Previous by thread: NSCollectionView item crashes when bound
  • Next by thread: Re: Modifying the save path in an NSDocument based application
  • Index(es):
    • Date
    • Thread