Re: How to check if file exists?
Re: How to check if file exists?
- Subject: Re: How to check if file exists?
- From: Quincey Morris <email@hidden>
- Date: Sat, 10 May 2014 16:19:27 -0700
On May 10, 2014, at 15:17 , Charles Srstka <email@hidden> wrote:
> Since that's the case Quincey was talking about (greying out files that don't exist in the UI), I'd say checkResourceIsReachableAndReturnError: is the appropriate API to use. It's certainly more efficient than reading the file just to see if it exists.
It might be the appropriate API, but its semantics are not entirely obvious. The documentation does not make clear what reachability means in the case of a file URL. Presumably, file systems are reachable if and only if they are mounted, but there’s surely a slight discomfort level with such an assumption. Maybe it’s just me.
Anyway, we weren’t suggesting reading the file just to see if it exists. We were suggesting reading the file if you’re going to read the file anyway. If you’re checking for existence, I think -[NSURL getResourceValue:forKey:error:] and -[NSURL resourcesValuesForKeys:error:] are good patterns to keep in mind, because in many cases you actually *do* want to know one or more resource values. For example, you might at least want to know whether the item is a file or a directory.
_______________________________________________
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