• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Filename encodings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Filename encodings


  • Subject: Filename encodings
  • From: Adam Maxwell <email@hidden>
  • Date: Sat, 10 Jul 2004 19:49:10 -0500

I've written a program to do find and replace on a list of filenames. It works quite well, but testing revealed problems with accented characters such as i in a filename. I've come up with a workaround, but I don't understand why it's necessary, and am curious if I'm missing something.

I run an NSOpenPanel, allow multiple file selection, get the selected file list as an NSArray, and send it to this method:

- (void)buildPathsArrayWithArray:(NSArray *)array{
NSEnumerator *e = [array objectEnumerator];
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:2];
NSString *oldPath = nil;
NSString *encodedPath = nil;
NSData *data;

while(oldPath = [e nextObject]){

data = [oldPath dataUsingEncoding:NSMacOSRomanStringEncoding];
encodedPath = [[[NSString alloc] initWithData:data encoding:NSMacOSRomanStringEncoding] autorelease];
// NSLog(@"encodedPath is %@", encodedPath);
[dict setObject:encodedPath forKey:@"Old Path"];
[dict setObject:@"" forKey:@"New Path"];
... do more stuff...
[pathsArray addObject:[dict copy]];
[dict removeAllObjects];
}
}

Unless I use NSMacOSRomanStringEncoding, things don't work right (I'm using the AGRegex framework for find/replace). I originally used the oldPath variable directly, and for a filename of "iagSGAMMA" (randomly chosen), my [pathsArray description] gave "e\U0301a\U0301c\U0327SGAMMA". After my NSMacOSRomanStringEncoding stuff, the array has "\U00e9\U00e1\U00e7SGAMMA" which actually works. Has anyone else run across this, or know of a better way to handle it?

thanks,
Adam Maxwell
_______________________________________________
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.


  • Follow-Ups:
    • Re: Filename encodings
      • From: Tito Ciuro <email@hidden>
  • Prev by Date: Re: Usb
  • Next by Date: Re: Applescript error - NSCannotCreateScriptCommandError
  • Previous by thread: Re: plist issues driving me crazy
  • Next by thread: Re: Filename encodings
  • Index(es):
    • Date
    • Thread