One Quickie


Moving a file to a tilde file (NSFIleManager->General)
    NSString *filename = @"/my/original/file/name";
    NSString *tildeFilename;
    tildeFilename = [NSString stringWithFormat: @"%@~", filename];

    // remove it first, otherwise the move will fail
    [defaultManager removeFileAtPath: tildeFilename
                    handler: nil];

    // now rename the file
    [defaultManager movePath: filename
                    toPath: tildeFilename
                    handler: nil];
If you want to stick the tidle before the file extension (so the finder could open ook~.tiff), try this:
	NSString *pathExtension = [filename pathExtension];
	if (!pathExtension) {
		tildeFilename = [filename stringByAppendingString: @"~"];
	} else {
		tildeFilename = [NSString stringWithFormat: @"%@~.%@", [filename stringByDeletingPathExtension], pathExtension];
	}
(Thanks to Peter Hosey for this one)



borkware home | products | miniblog | rants | quickies | cocoaheads
Advanced Mac OS X Programming book

webmonster@borkware.com