Objective-C Foundation framework Example: Looking for Files, objectivec

Source: Internet
Author: User

Objective-C Foundation framework Example: Looking for Files, objectivec

Objective-C Foundation framework Example: Looking for Files

NSFileManager. The NSFileManager class lets you do stuff with the file system, like create directories, remove files, move files around, and get information about files.

NSFileManager: allows you to process file system tasks, such as creating directories, removing files, moving files, and obtaining file information.

 

 

//// Main. m // Helloworld /// Created by kfx on 15-5-4. // Copyright (c) 2015 com. mySuperCompany. all rights reserved. // # import <Foundation/Foundation. h> int main (int argc, const char * argv []) {@ autoreleasepool {NSFileManager * manager; manager = [NSFileManager defaultManager]; NSString * home; home = [@"~ "Outputs]; NSDirectoryEnumerator * direnum; // directory enumeration direnum = [manager enumeratorAtPath: home]; NSMutableArray * files; files = [NSMutableArray arrayWithCapacity: 42]; NSString * filename; while (filename = [direnum nextObject]) {if ([[filename pathExtension] isdue to: @ "jpg"]) {[files addObject: filename] ;}} NSEnumerator * fileenum; fileenum = [files objectEnumerator]; while (filename = [fileenum nextObject]) {NSLog (@ "% @", filename) ;}} return 0 ;}

 

  

 

Return 0;

}

 

 

 

Where in the file system to start looking at files?

Starting from the top level of your hard drive cocould take a long time, so let's just look in your home directory.

Start in the home directory.

Luckily, Unix (and OS X) has a shorthand character for the home directory, which is ~ (Also known as the tilde ).

Unix and OS x have a simple string representing the home directory.

Related Article

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.