-(BOOL) Fileexistsatpath: (NSString *) path isdirectory: (BOOL *) isdirectory
In general, the iOS system determines whether a file or directory exists, you can use the above API.
The second parameter, Isdirectory, is an outgoing parameter that returns whether it is a file or a directory.
This API is used in two general cases
Need to determine whether a file or directory exists
Demand two. Determine if path is a file or directory
Requirement one, as long as the return value of the API is determined, yes exists, no is not exist, isdirectory do not need to judge
Because when the incoming parameter path does not exist, Isdirectory returns undefined, and if you do not want to determine whether the directory, this parameter can be passed null. Looking at an example on the Web, it also determines the bool value of a file or directory if it exists. is actually wrong, because there is a third value undefined.
Isdirectory
Upon return, contains YES if path is a directory or if the final path element is a symbolic link this points to a Director Y, otherwise contains NO. If path doesn ' t exist, this value is undefined upon return. Pass NULL If you don't need this information.
In particular, it is interesting to
When path looks like a directory string, the values returned by IOS6 and 7 and 8,isdirectory are different.
IOS 6.1 For this undefined, judged no,
While IOS7 and 8, return Yes
This problem caused, if using isdirectory, in the iOS6.1 system, is unable to determine a nonexistent path, it is a file or folder. Just rely on the return value of this API to determine
The analysis of this paper is mainly to solve the iOS6 and follow-up system, the details of the same API call processing. For reference only.
Need two to determine if path is a file or directory
According to the analysis of demand one
If you want to determine if path is a file or a directory, in iOS6.1, you need to make sure that path exists. Then it should actually be a two-step operation.
First Call-(BOOL) Fileexistsatpath: (NSString *) path isdirectory: (BOOL *) Isdirectory, based on the return value, determine if there is
If present, make a second call.
Second call-(BOOL) Fileexistsatpath: (NSString *) path isdirectory: (BOOL *) isdirectory, according to Isdirectory, determine whether the directory
Determine if a sandbox file or directory exists, and whether a file or directory is a hidden problem