Re: Re: Append to file with NSString writeToFile:
Re: Re: Append to file with NSString writeToFile:
- Subject: Re: Re: Append to file with NSString writeToFile:
- From: <email@hidden>
- Date: Mon, 28 Feb 2005 7:54:00 +0000
> From: Magnus Strand <email@hidden>
> Hi James,
>
>
> I haven't tried this myself but perhaps you can call
>
> NSFileHandle method seekToEndOfFile before the call to writeToFile.
>
> Magnus
>
Thanks for the suggestion, Magnus. I have, in fact, tried something to that effect, but while it compiled with no errors, when I ran it, the file itself was not even created. This is the code I am using:
NSString* pathToWrite = @"/Users/James/Desktop"; // this is arbitrary, the actual filename comes from a SavePanel
// alloc and init NSTask and NSPipe
NSFileHandle* fileReader = [myPipe fileHandleForReading];
NSFilehandle* fileWriter = [NSFileHandle fileHandleForWritingAtPath:pathToWrite];
[fileWriter truncateFileAtOffset:[fileWriter seekToEndOfFile]];
// set task arguments and output
[myTask launch];
[fileWriter writeData:[fileReader readDataToEndOfFile]];
But this presents me with several problems. First off, this implementation did not even create a file on my Desktop. Second of all, I would like to be able to catch each output of each file and prepend the file name to it before it is written to file.
I also have code that simply takes the string, inits it from the data and writes to file as such:
NSString* output = [[NSString alloc] initWithData:[fileReader readDataToEndOfFile] encoding:NSASCIIStringEncoding];
// create another string with filename info and append output.
[fingerprint writeToFile:pathToWrite atomically:YES];
This will create the file and write the info in the format I want, but it overwrites the previous info. Not sure how to handle this.
James
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden