• 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
Re: Renaming files?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Renaming files?


  • Subject: Re: Renaming files?
  • From: Christoffer Lerno <email@hidden>
  • Date: Tue, 21 Dec 2004 12:20:29 +0100


On Dec 20, 2004, at 20:10, Clark Cox wrote:

On Mon, 20 Dec 2004 18:01:14 +0100, Christoffer Lerno <email@hidden> wrote:
I thought I had renaming files nailed down by using NSFileManager's
movePath:toPath:handler: but it has problems with spaces & non ascii
characters in filenames - the documentation unfortunately doesn't
reveal how this is circumvented.

Where are you getting the filenames from? As a test, I just used
NSFileManager to rename a file whose name contained several accented
characters, a Japanese character and several spaces. It went off
without a hitch. I suspect that there is something wrong with the way
that you're obtaining your filenames.

You're right, it's working. It turns out the problem was a wee bit more complicated. Basically I take an NSString obtained from an NSTextField and put that together with the path to the working directory and do a movePath:toPath:handler: which works fine.

What turns out to be the problem is that when I later get the filenames with NSFileManager's directoryContentsAtPath:, then these filenames will be different from the NSStrings I started out with. Or rather, using isEqual: says they're different, compare: says they are the same. Unfortunately most routines don't rely on compare...

The following code illustrates the problem:

int main(int argc, char *argv[])
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSString *originalPath = [@"~/Desktop/renametest.txt" stringByExpandingTildeInPath];
NSString *destinationPath = [@"~/Desktop/å ä ö.txt" stringByExpandingTildeInPath];
[[NSFileManager defaultManager] removeFileAtPath:originalPath
handler:nil];
[[NSFileManager defaultManager] removeFileAtPath:destinationPath
handler:nil];
[[NSFileManager defaultManager] createFileAtPath:originalPath
contents:[NSData data]
attributes:nil];
if (![[NSFileManager defaultManager] fileExistsAtPath:originalPath])
{
NSLog(@"Incorrect, the file %@ should exist before rename.",originalPath);
}
if ([[NSFileManager defaultManager] fileExistsAtPath:destinationPath])
{
NSLog(@"Incorrect, the file %@ should not exist before rename.",destinationPath);
}
[[NSFileManager defaultManager] movePath:originalPath
toPath:destinationPath
handler:nil];
if ([[NSFileManager defaultManager] fileExistsAtPath:originalPath])
{
NSLog(@"Incorrect, the file %@ should not exist after rename.",originalPath);
}
if ([[NSFileManager defaultManager] fileExistsAtPath:destinationPath])
{
NSLog(@"Incorrect, the file %@ should exist after rename.",destinationPath);
}
[pool release];
return 0;
}
 _______________________________________________
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

  • Follow-Ups:
    • Re: Renaming files?
      • From: Clark Cox <email@hidden>
References: 
 >Renaming files? (From: Christoffer Lerno <email@hidden>)
 >Re: Renaming files? (From: Clark Cox <email@hidden>)

  • Prev by Date: Re: To Draw fine rectangle
  • Next by Date: Cocoa and bit handling
  • Previous by thread: Re: Renaming files?
  • Next by thread: Re: Renaming files?
  • Index(es):
    • Date
    • Thread