File: programming/cocoa/Filie.zip/Filie/UliKit/NSFileManager NameForTempFile.m


/* =============================================================================
    PROJECT:    Filie
    FILE:       NSFileManager+NameForTempFile.m
    
    PURPOSE:    Assorted unique-filename-generation methods.
    
    COPYRIGHT:  (c) 2004 by M. Uli Kusterer, all rights reserved.
    
    AUTHORS:    M. Uli Kusterer - UK
    
    LICENSES:   GNU GPL, Modified BSD
    
    REVISIONS:
        2004-02-08  UK  Created.
   ========================================================================== */
 
// -----------------------------------------------------------------------------
//  Headers:
// -----------------------------------------------------------------------------
 
#import "NSFileManager+NameForTempFile.h"
// -----------------------------------------------------------------------------
//	nameForTempFile:
//		Quickly generates a (pretty random) unique file name for a file in the
//		NSTemporaryDirectory and returns that path. Use this for temporary
//		files the user will not see.
//
//	REVISIONS:
//		2004-03-21	witness	Documented.
// -----------------------------------------------------------------------------
"temp_%i"// -----------------------------------------------------------------------------
//	uniqueFileName:
//		Takes a file path and if an item already exists at that path, generates
//		a unique file name by appending a number. Use this to e.g. add files
//		to user-owned folders (like the desktop) to ensure you don't overwrite
//		any valuable data.
//
//      May return NIL if it's searched for a while (after about 2 billion
//      attempts).
//
//	REVISIONS:
//		2004-03-21	witness	Documented.
// -----------------------------------------------------------------------------
// Keep looping until we have a unique name:
// Build "/folder/file 1"-style path:
" %i"// Build "/folder/file 1.suffix"-style path:
" %i.%@"// overflow!
 

This code uses the PclZip Zip File reading code, which is subject to the GNU LGPL. It also uses the GeSHi syntax highlighter, subject to the GPL. Ask if you want this for your own web site, it's free.