OBJECT-C, File path API

Source: Internet
Author: User

Sharp Spit Groove

1. also " file and directory operations ", in Java , using a java.util.File class, It encapsulates a lot of APIs, and object-c has so many classes and functions. Specific reasons, need to be analyzed AH.

2. clearly is nsstring, string operation, how to appear "pathcomponents" such as manipulating file path related methods, very strange bright.

3.stringByAppendingString , the name of the function is a bit long.

4. Overall feeling,object-c syntax is more complicated than Java , Code code efficiency is much lower.


/
main.m//filepathutil////Created by fansunion on 15/11/29.//Copyright (c) 2015 demo. All rights reserved.//#import <foundation/foundation.h>//Demo file path apiint main (int argc, const char * argv[]) {@auto        Releasepool {nsstring *filename [email protected] "PATH.M";        Nsfilemanager *FM;        NSString *path,*tempdir,*extention,*homedir,*fullpath;                        Nsarray *components;        FM =[nsfilemanager Defaultmanager];        Temp directory tempdir = nstemporarydirectory ();                NSLog (@ "The TempDir is%@", tempdir);        Extracting the base directory path =[FM Currentdirectorypath];                NSLog (@ "The base dir is%@", [path lastpathcomponent]); The full path of filename in the current directory//This place has a problem//local output "/USERS/FANSUNION/LIBRARY/DEVELOPER/XCODE/DERIVEDDATA/FILEPATHUTIL-BV ZJQEHOTBEXOOEBRUPHTWCMQEKZ/BUILD/PRODUCTS/DEBUGPATH.M "There is no" delimiter "/" between//debug and PATH.M, and the examples in the book are/are best or manually added, in Java There is also no this delimiter, need to manually add the FullPath =[path StringbyappEndingstring:filename];                NSLog (@ "The FullPath is%@", FullPath);        Get file extension extention = [FullPath pathextension];                NSLog (@ "The extentions is%@", extention);        Get the user's home directory homedir = Nshomedirectory ();        NSLog (@ "The home directory is%@", homedir);        The split path is the components of each component = [Homedir pathcomponents];        for (path under Components) {NSLog (@ "%@", Path); }} return 0;}

Program output

2015-11-29 13:43:30.550 filepathutil[2861:179163] the tempdir is/var/folders/4q/5ylpds9n5n97bq_r41qvly4w0000gn/t/

2015-11-29 13:43:30.551 filepathutil[2861:179163] The base dir is Debug

2015-11-29 13:43:30.551 filepathutil[2861:179163] the FullPath is/users/fansunion/library/developer/xcode/ Deriveddata/filepathutil-bvzjqehotbexooebruphtwcmqekz/build/products/debugpath.m

2015-11-29 13:43:30.551 filepathutil[2861:179163] The extentions is M

2015-11-29 13:43:30.552 filepathutil[2861:179163] the home directory is/users/fansunion

2015-11-29 13:43:30.552 filepathutil[2861:179163]/

2015-11-29 13:43:30.552 filepathutil[2861:179163] Users

2015-11-29 13:43:30.553 filepathutil[2861:179163] Fansunion

Program ended with exit code:0


OBJECT-C, File path API

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.