• 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: Um... How do you rename a file?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Um... How do you rename a file?


  • Subject: Re: Um... How do you rename a file?
  • From: p3consulting <email@hidden>
  • Date: Fri, 26 Mar 2004 10:17:15 +0100

A latest small point:
case-sensitivity of the target file system may influence the success or
failure of a rename operation according to
the system call used by the application:
Finder (Carbon application) is successfull at renaming a file to
another case spelling: eg "foo" to "Foo"
where ProjectBuilder and Xcode (Cocoa application) both fail to.

In consequence, moving files from a case-sensitive file system to a
non-case sensitve one may turn out to be a tricky operation:
the set of files ("foo", "Foo") will generate the set of results
("foo", failure) if movePath:toPath is used.

For that particular aspect movePath:toPath is NOT equivalent to mv.

in Terminal.app

touch /tmp/Foo
mv /tmp/Foo /tmp/foo
ls /tmp/foo
/tmp/foo

when compiling and executing the following code

#import <Foundation/Foundation.h>

@interface FileErrorHandler : NSObject
{
}

- (BOOL)fileManager:(NSFileManager *)manager
shouldProceedAfterError:(NSDictionary *)errorInfo;

@end

@implementation FileErrorHandler

- (BOOL)fileManager:(NSFileManager *)manager
shouldProceedAfterError:(NSDictionary *)errorInfo
{
NSLog(@"%@",errorInfo);
return NO ;
}

@end

int main(int argc, char **argv)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]
;
FileErrorHandler *errHandler = [[FileErrorHandler alloc] init]
;

[[NSFileManager defaultManager] movePath:@"/tmp/Foo"
toPath:@"/tmp/foo" handler:errHandler] ;

[pool release] ;
return 0 ;
}

generates

2004-03-26 10:08:57.435 a.out[2091] <CFDictionary 0x5078c0
[0xa01900e0]>{type = immutable, count = 2, capacity = 2, pairs = (
0 : <CFString 0xa09f62f0 [0xa01900e0]>{contents = "Error"} =
<CFString 0xa09f63d0 [0xa01900e0]>{contents = "Already Exists"}
2 : <CFString 0xa09f62e0 [0xa01900e0]>{contents = "Path"} =
/tmp/Foo
)}

Pascal Pochet
email@hidden



Le 25 Mar 2004, ` 13:29, Alastair Houghton a icrit :

> On 25 Mar 2004, at 11:47, Ken Tozier wrote:
>
>> I'll try that, thanks.
>>
>>> I don't understand why you rule out movePath:toPath? It seem to me
>>> that it is the equivalent of a "mv" shell command, which is a rename
>>> operation, as well as a move operation. Isn't it obvious that
>>> "destination must not yet exist", if you're going to rename a file?
>>
>> I'm not a unix guy, so, to me, move (or mv) means physically transfer
>> a
>> file to a completely different location.
>>
>> The documentation states two things which seem in clear conflict (or
>> at
>> least extremely wasteful) as I read it
>>
>> 1. "the method CREATES a file at destination that holds the exact
>> contents of the original file and then DELETES the original file"
>
> Yes, that is notionally how it works. This doesn't conflict in any way
> with the idea of a rename, and the idea that it must be doing this by
> copying all of the data is something that you are reading into it... it
> certainly doesn't say that. (It only needs to copy if it's moving
> across filesystems or on a filesystem without hard links and with no
> special support for rename.)
>
>> 2. The file specified in source must exist, while destination must not
>> yet exist.
>
> I don't see how that conflicts either. If I have two files, "foo" and
> "bar" in a directory, I shouldn't be allowed to rename "foo" to "bar"
> because "bar" already exists. Seems to make sense to me.
>
>> This says to me that the system creates a new file at destination and
>> copies the entire contents no matter how many tens or hundreds of
>> megabytes it might be, then deletes the original. I'm sure it's not,
>> but that how it reads. Contrast that with:
>>
>> [aFile setName:@"jim bob"]
>>
>> Done. Much easier and much more intuitive than moving a file you're
>> not
>> really moving.
>
> I take your point about the fact that you aren't really moving the file
> so you don't expect to have to use a method called "move". But I'm
> sure you can see that renaming a file is just a special case of the
> move operation in which you don't change the directory that it's in ---
> i.e. there's no need for a separate rename operation.
>
> Kind regards,
>
> Alastair.
>
> --
> http://www.alastairs-place.net
>
> [demime 0.98b removed an attachment of type
> application/pkcs7-signature which had a name of smime.p7s]
> _______________________________________________
> 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.


  • Follow-Ups:
    • Re: Um... How do you rename a file?
      • From: Alastair Houghton <email@hidden>
References: 
 >Re: Um... How do you rename a file? (From: Ken Tozier <email@hidden>)
 >Re: Um... How do you rename a file? (From: Alastair Houghton <email@hidden>)

  • Prev by Date: Completely resizing NSImage
  • Next by Date: Re: Um... How do you rename a file?
  • Previous by thread: Re: Um... How do you rename a file?
  • Next by thread: Re: Um... How do you rename a file?
  • Index(es):
    • Date
    • Thread