
#import "TempFilename.h"

@implementation NSFileManager (TempFilename)

- (NSString *)tempFilenameExt:(NSString *)pathExt
{
    NSFileManager *fm = [NSFileManager defaultManager];
    NSString *name, *tempdir = NSTemporaryDirectory();

    unsigned long count = 0;
    do {
	NSString *temp = [NSString stringWithFormat:@"%08X", count++];
	name = [tempdir stringByAppendingPathComponent:temp];
	
	if(pathExt!=nil){
            name = [name stringByAppendingPathExtension:pathExt];
	}
    } while([fm fileExistsAtPath:name]==YES);

    return name;
}

@end
