Determine if a sandbox file or directory exists, and whether a file or directory is a hidden problem

Source: Internet
Author: User

-(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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.