• 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
Re: Re: Append to file with NSString writeToFile:
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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 9:03:47 +0000

>
> From: Harilaos Skiadas <email@hidden>
> I.e. create the file you want to put all your info in,
> open it and attach file handle to it, use this handle
> to send all the data from all the files your other
> task is processing, and then when you are done close
> the file and clean up.

Maybe this is the part where I'm confused.  Here is the relevant code:

First off, the file to write to is actually chosen in a save panel, so first I do this:

int i;
NSString* fingerprintPath = [savePanel filename];

// since I'm processing an array of files...
for (i = 0; i < [convertedFiles count]; i++)
{
   NSString* fileToConvert = [convertedFiles objectAtIndex:i];
   NSArray* arguments = [[NSArray alloc] initWithObjects:@"--show-md5", fileToConvert, nil];

   [NSApp beginSheet:md5Sheet modalForWindow:mainWindow modalDelegate:self didEndSelector:NULL contextInfo:nil];

   myTask = [[NSTask alloc] init]; // properly declared
   myPipe = [[NSPipe alloc] init]; // properly declared
   fileReader = [myPipe fileHandleForReading]; // same
   fileWriter = [NSFileHandle    fileHandleForWritingAtPath:[self FLACfilePath]]; // same

   [myTask setLaunchPath:execPath];
   [myTask setArguments:arguments];
   [myTask setStandardOutput:myPipe];

[myTask launch];

   // this gets the output of the process into a string.
   NSString* output = [[NSString alloc] initWithData:[fileReader readDataToEndOfFile] encoding:NSASCIIStringEncoding];

   // this basically gets the filename only
   NSString* fingerprint = [[NSString alloc] initWithString:[fileToConvert lastPathComponent]];

   // this results in filename:output
   fingerprint = [[fingerprint stringByAppendingString:@":"] stringByAppendingString:output];

   [fileWriter seekToEndOfFile];
   [fileWriter writeData:[fingerprint dataUsingEncoding:nil]];

   [myTask release];
   [myPipe release];
}

So basically I've got an array of strings, each representing an audio file that's just been converted to FLAC (lossless audio).  Now we want to basically get a fingerprint of each file to ensure it has been compressed correctly.  This will later be verified with another process.

Each file is processed creating a unique output (basically a long string of alphanumeric characters).  I prepend this information with the filename, and write it to a file.  But when I run the above code, no file is created.  I know I have the task set up correctly because when I use NSString's writeToFile:atomically: method on the string itself, it correctly produces the output and writes the info to the file.  But each pass overwrites the previous info.

Am I missing something here?  Am I doing this correctly?  Thanks.

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

  • Prev by Date: Changing initial value of isDocumentEdited
  • Next by Date: Re: Changing initial value of isDocumentEdited
  • Previous by thread: Re: Append to file with NSString writeToFile:
  • Next by thread: Re: Append to file with NSString writeToFile:
  • Index(es):
    • Date
    • Thread