• 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: Creating temporary files?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Re: Creating temporary files? (From: Sherm Pendley <email@hidden>)

  • Prev by Date: Funny NSDateFormatter behaviour
  • Next by Date: Re: Protecting Software w/ Software License Keys...
  • Previous by thread: Re: Creating temporary files?
  • Next by thread: Re: Creating temporary files?
  • Index(es):
    • Date
    • Thread