Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MrFusion

macrumors 6502a
Original poster
Jun 8, 2005
613
0
West-Europe
Hey,

I am trying to save a document as a package. As a test I wanted to save a plaintext file inside a directory. So I created a new project (cocoa document based) and added to following code (see below).
I also edited the target to set the name, extensions and such.

But when I try to save, I still get a sheet saying this is not possible. No files are actually saved either.
I would prefer not to use filewrapper (save everything in once), as my program will increasingly add files to the package, but will not edit them
afterwards.

Thanks.
PS. I tried google, but couldn't find anything useful for me. I did find the same question, but alas without an answer.

- (BOOL)writeToFile:(NSString *)fileName ofType:(NSString *)docType
{
NSLog(@"%@",docType);
NSString *str = @"qwerty";
NSData *mydata = [str dataUsingEncoding:NSUTF8StringEncoding];
[mydata writeToFile:[NSString stringWithFormat:mad:"%@/%@",fileName,@"test"]
atomically:0];
return YES;
}
 

iSee

macrumors 68040
Oct 25, 2004
3,539
272
I'm not sure, but here is one thing to check:

Will your sample code work if the folder already exists? I'm wondering if it is failing because the file you are trying to write to is in a folder that doesn't exist.

If it works when the folder already exists, then you can modify your code so that it first checks to see if the folder exists and create it if it doesn't.

Good luck :)
 

MrFusion

macrumors 6502a
Original poster
Jun 8, 2005
613
0
West-Europe
iSee said:
I'm not sure, but here is one thing to check:

Will your sample code work if the folder already exists? I'm wondering if it is failing because the file you are trying to write to is in a folder that doesn't exist.

If it works when the folder already exists, then you can modify your code so that it first checks to see if the folder exists and create it if it doesn't.

Good luck :)

If the folder exist, it can be opened. It does disappear when trying to overwrite it.
Checking to see if the folder needs to be created before writing to it says that it is present. However, the fileName passed to the method is some temporary one and not the location I specified. It is a folder located somewhere in /private/var/tmp/....
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.