[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Copying files with special characters
From: |
Sheldon Gill |
Subject: |
Re: Copying files with special characters |
Date: |
Wed, 10 Sep 2008 12:48:52 +0800 |
User-agent: |
Thunderbird 2.0.0.16 (Windows/20080708) |
Andreas Höschler wrote:
Dear all,
I would like to programmatically copy files with
system([[NSString stringWithFormat:@"cp -r %@ %@", sourcePath,
destPath] cString]);
or alternatively using NSFileManager. This works as long as sourcePath
does not contain special characters like ä,ö,ü,...
In a terminal shell I can successfully copy such a file by typing
cp "Germ
and then using TAB to automatically complete the path to
cp "German Fa\314\210hrhaus.jpeg" /home/ahoesch/A00
The question for me now is where this magic \314\210 stuff comes from
and how I can do the conversion in my GNUstep app programmatically
before building the copy command.
That's your shell auto-completion routine returning the appropriate
codes for the character(s). What locale are you using?
I'd have guessed your file name is Fährhaus (aber mein deutsch ist
schlect) in which case
Decomposed UTF8 should have the following character as U+00A8
(Diaeresis) if I'm not mistaken.
Precomposed UTF8 should not have the 'a' but simply the character U+00E4
(Latin small A with diaeresis)
but your shell completion is returning two characters which I can't make
sense of.
system([[NSString stringWithFormat:@"cp -r %@ %@", [sourcePath
magicMethod], destPath] cString]);
Hints are greatly appreciated!
I think the correct *step way would be:
BOOL did_copy;
NSString sourcePath = @"German Fährhaus.jpeg";
NSString destPath = [[NSHomeDirectory()] stringByAppendingPathComponent:
@"A00"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath: sourcePath])
{
did_copy = [fileManager copyPath:sourcePath
toPath:destPath
handler:nil];
}
If this doesn't work on your system, please file a bug as it should work
everywhere GNUstep does. That said, it would appear to be a problem
with your OS/locale combination.
On a modern *nix you should be able to get away with:
system([[NSString stringWithFormat:@"cp -r %@ %@", [sourcePath UTF8String],
[destPath UTF8String]]);
but I wouldn't recommend going down that route. The file manager methods
should do the right thing.
Regards,
Sheldon
Checked for Virus & Spam by West Australian Networks Internet Service Providers
see www.westnet.net.au