Renaming and moving files
Renaming and moving files
- Subject: Renaming and moving files
- From: Andreas Schwarz <email@hidden>
- Date: Thu, 7 Mar 2002 20:25:17 -0800
Is there any way in Cocoa to rename files? Or move them in a logical
manner?
Apparently not. I read all this (and other) list's archives a long time
ago (and again today) and all I saw suggested were NSFileManager's
movePath:toPath: and the rename() function. I decided to go with the
Cocoa solution, despite the fact it necessitated an intermediate step
whe renaming a file with just a case change. Seemed to me to work fine
for the most part...
Today it bit me mighty hard. I wanted to see what kind of error message
it returned when attempting to rename a file I didn't have permission to
rename, and I stupidly decided to test it on the Applications folder
(which I should have realized I had permission to but at the moment it
just seemed to me like it would be an unrenameable folder). So I tried
to rename it "Applications two" and... churn churn churn... 40 or so
error messages (I guess I got my wish)... more churning... many more
errors... more churning...
Fifteen minutes later when the errors stopped and the hard drive calmed
down, I was left with ONE app in the Applications folder named
"del0661.72c" (it was System Prefs, and it actually ran fine). No
"Applications two" folder at all. Everything gone.
Prompted by this I went back and took a closer look at the docs and it
seems that movePath:toPath: actually *copies* everything and then
deletes the originals (yes, I know, I should have paid more attention,
but that seems so insanely purposeless and wasteful to me, I just
assumed movePath:toPath: would function in a more logical manner and
didn't give too close a look at the docs. My fault I guess). Nice how
the deleting worked just fine for me but the copying didn't. (And don't
tell me to file a bug, I am unable to log in to the bug reporter even
though my adc login/pass works fine everywhere else. I'd file a bug on
that but.... ;-).
So my questions:
1) Is there any way to move a file in a more sensible fashion (ie.
without copying everything if the move is within the same volume)?
2) What is the best way to rename a file? Does rename() work on any
filesystem?
Should I perhaps look into using Carbon instead? That's what I'm
thinking about now.
Sorry for the long message and thanks for your help!
Andreas Schwarz
_______________________________________________
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.