• 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: Problem with NSFileManager
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with NSFileManager


  • Subject: Re: Problem with NSFileManager
  • From: Ken Thomases <email@hidden>
  • Date: Wed, 2 Sep 2009 14:41:12 -0500

Moving this to Cocoa-Dev where it's appropriate...

On Sep 2, 2009, at 1:50 PM, K. Chen wrote:

I ran into a weird situation with NSFileMnager.

First my code want to see if a file already exists
if (![fileManager fileExistsAtPath:myConfigFile])
the result is NO, so my code goes into the if block

Then my code tries to copy the file over from the bundle; note the the destination is under <app_home>/Documents.
if (![fileManager copyItemAtPath:configFilePath toPath:myConfigDir error:&err])
Here I got the error message from [NSError localizedDescription] saying: Operation could not be completed. File exists.


Well first FM told me the file doesn't exist and then when I tried to copy, it said it already exists???

Well, you're checking myConfigFile but then copying to myConfigDir. Based on the docs for the older -copyPath:toPath:handler: method, I don't think -copyItemAtPath:toPath:error: implicitly creates a same- named file in the destination directory. The destination is taken literally. Since the directory does exist, that explains the error. So, you need to copy to myConfigFile rather than myConfigDir.


You should also just abandon the check for the existence of myConfigFile in advance. It doesn't help, since some other process can create the file between when you check for it and when you try to create it with the copy. Just attempt the copy and cope with a failure due to a file existing at the destination.

Regards,
Ken

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: Core Data migration from xml to sqlite
  • Next by Date: Contextual Menus in Snow Leopard
  • Previous by thread: Re: What's the purpose of the "fax" received action?
  • Next by thread: Contextual Menus in Snow Leopard
  • Index(es):
    • Date
    • Thread