Re: Renaming files?
Re: Renaming files?
- Subject: Re: Renaming files?
- From: Jeremy Dronfield <email@hidden>
- Date: Wed, 22 Dec 2004 14:03:42 +0000
On 22 Dec 2004, at 9:56 am, Christoffer Lerno wrote:
You're right (as I said to Clark Cox) it turns out that the encoding
is different in the filenames when I get them back. Try taking
new00002.tiff, name it
“!”•¶ ^^ é @£## {€} %\<> .gif by using movePath:toPath:handler: and
then compare the NSString you kept the new filename in with the
filenames gotten from - (NSArray *)directoryContentsAtPath:(NSString
*)path
It would seem that they have different encodings the filenames won't
match unless I use compare (isEqualToString doesn't work)
I wonder if there is some way to take my NSString from the NSTextField
and convert that to the filesystem-encoding so they match up with
isEqualToString?
The reason -isEqualToString: doesn't work is nothing to do with
non-ASCII characters in general. It has to do specifically with
composed character sequences. (Try doing the above example without the
"é" and it should work.) -isEqualToString: performs a case-sensitive
comparison - in other words, it does the same thing as compare:options:
with NSLiteralSearch specified in options:. And from the documentation
for NSLiteralSearch, "Differing literal sequences (such as composed
character sequences) that would otherwise be considered equivalent are
considered not to match."
For filename/path comparisons of the kind you're doing, use a
case-insensitive compare. There is another reason for this: the file
system is case-insensitive. -isEqualToString: will tell you that
"myImage.jpg", "MyImaGe.jpg" and "MYIMAGE.JPG" are all different,
whereas the file system considers them identical.
On 21 Dec 2004, at 11:20 am, Christoffer Lerno wrote:
Unfortunately most routines don't rely on compare...
I'm not sure what you mean by this. Take the following example using my
own file renaming application as a basis:
renameSuccess = [manager movePath:oldPath toPath:newPath handler:nil];
/*experiment*/
NSArray *contents = [manager directoryContentsAtPath:[newPath
stringByDeletingLastPathComponent]];
id file;
NSEnumerator *fileEnum = [contents objectEnumerator];
while (file = [fileEnum nextObject]) {
NSComparisonResult result = [file caseInsensitiveCompare:[newPath
lastPathComponent]];
NSLog(@"file:%@", file);
NSLog(@"new name:%@", [newPath lastPathComponent]);
if (result == NSOrderedSame)
NSLog(@"match");
else
NSLog(@"no match");
if (![manager fileExistsAtPath:newPath])
NSLog(@"newPath doesn't exist");
else
NSLog(@"newPath exists");
if (![manager fileExistsAtPath:[[newPath
stringByDeletingLastPathComponent]
stringByAppendingPathComponent:file]])
NSLog(@"file doesn't exist");
else
NSLog(@"file exists");
}
/*experiment*/
Log output:
2004-12-22 13:51:11.959 Skooby Renamer[560] file:∆ƒ éü I ^&*
§¶•0001.jpg
2004-12-22 13:51:11.959 Skooby Renamer[560] new name:∆ƒ éü I ^&*
§¶•0001.jpg
2004-12-22 13:51:11.959 Skooby Renamer[560] match
2004-12-22 13:51:11.960 Skooby Renamer[560] newPath exists
2004-12-22 13:51:11.960 Skooby Renamer[560] file exists
Hope this helps. Regards,
Jeremy
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden