RE: Rename files containing a slash
RE: Rename files containing a slash
- Subject: RE: Rename files containing a slash
- From: "Josh Ferguson" <email@hidden>
- Date: Mon, 21 Oct 2002 13:39:46 -0500
- Thread-topic: Rename files containing a slash
Lorenzo,
You need to keep in mind the fact that the file system and the finder are seperate. In other words, the file system does not allow you to have a "/" in the name, while the finder does. Likewise, the finder does not allow you to have a ":" in the name while the file system does. When a user enters a name a file name in the finder (i.e. MY/FILE), the file system actually stores it with a colon (MY:FILE). This can be verified from the terminal. I would GUESS (don't know since I know as little about Carbon as possible) this is at the root of your problem.
As far as renaming a file from Cocoa goes, you have to think like a unix person. When you want to rename a file from the terminal you typically just "mv" (move) the file from its current name to the new name, as opposed to renaming it (i.e mv MY:FILE YOUR:FILE will rename MY:FILE to YOUR:FILE). You could do the same thing with NSFileManager's -movePath:toPath:handler method.
HTH,
Josh Ferguson
-----Original Message-----
From: Lorenzo Puleo [
mailto:email@hidden]
Sent: Monday, October 21, 2002 1:19 PM
To: Cocoa Development List
Subject: Rename files containing a slash
Hi,
I'm trying to rename a file using a new filename containing a slash.
Since I can't find a Cocoa API that renames files I use the Carbon API:
err = FSRenameUnicode(&destRef, nameLength, name, theInfo.textEncodingHint,
nil);
Each time the fileName proposed contains a slash (that Finder accepts) this
API returns an error. Please may someone help me to fix the trouble?
Thank you.
--
Lorenzo Puleo
mailto:email@hidden
- (BOOL)RenameItem:(NSString*)dest sourceItem:(NSString*)source
{
OSErr err;
UniChar name[256];
UniCharCount nameLength;
FSRef sourceRef, destRef;
FSCatalogInfo theInfo;
NSString *newName = [source lastPathComponent];
// Righ now the variable source seem to contain a ":"
// instead of the slash
NSLog(@"Rename With Source %@", source);
nameLength = [newName length];
[newName getCharacters:name];
err = FSPathMakeRef([source fileSystemRepresentation], &sourceRef,
NULL);
if(err) return NO;
err = FSGetCatalogInfo(&sourceRef, kFSCatInfoTextEncoding, &theInfo,
nil, nil, nil);
if(err) return NO;
err = FSPathMakeRef([dest fileSystemRepresentation], &destRef, NULL);
if(err) return NO;
err = FSRenameUnicode(&destRef, nameLength, name,
theInfo.textEncodingHint, nil);// //kTextEncodingUnknown
if(err) return NO;
return YES;
}
_______________________________________________
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.
_______________________________________________
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.