Re: Creating temporary files?
Re: Creating temporary files?
- Subject: Re: Creating temporary files?
- From: Dinu Gherman <email@hidden>
- Date: Sat, 22 Jun 2002 10:42:48 +0200 (CEST)
Sherm Pendley <email@hidden>:
>
> Isn't there some standard way to create a temp file
>
>
Check out the C functions tmpfile() and tmpnam().
I'm surprised it's not been wrapped with Cocoa code, but ok,
something like this category below seems to work well enough.
You can add custom contents: and attributes: parameters if
you need them...
Dinu
// FileManagerAdditions.m
#include <unistd.h>
#import "FileManagerAdditions.h"
@implementation NSFileManager (FileManagerAdditions)
- (NSString *)createTempFileWithTemplate:(NSString *)pathTemplate
{
NSString *tmpPath = [NSString stringWithCString: mktemp((char
*)[pathTemplate cString])];
NSFileHandle *tmpFile = [NSFileHandle fileHandleForWritingAtPath: tmpPath];
[self createFileAtPath: tmpPath contents: nil attributes: nil];
tmpFile = [NSFileHandle fileHandleForWritingAtPath: tmpPath];
if ([self fileExistsAtPath: tmpPath])
return tmpPath;
else
return nil;
}
@end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.