Objective-c Learning-Finding files

Source: Internet
Author: User

Ocstudy

Main.m

//

Starting from the home directory, find the path to all files with the file extension jpg

Created by Mark on 11-10-30.

Copyright 2011 __mycompanyname__. All rights reserved.

//


#import <Foundation/Foundation.h>


int main (int argc, const char * argv[])

{


@autoreleasepool {

Nsfilemanager *manger;

Manger =[nsfilemanager defaultmanager];//Build a File Manager

NSString *home;

home= [@ "~" stringbyexpandingtildeinpath];//~ is a shorthand for the home directory, this method call is to specify the home directory to the home

Nsmutablearray *file;

FILE = [Nsmutablearray arraywithcapacity:42];//creates a new mutable array, 42 is random, does not affect the array extension, you can also write 41, as you like

For (NSString *filename in [Manger Enumeratoratpath:home]) {//Traverse each file path to find the file with the extension jpg, The Fast enumeration method makes it easier and quicker to access each element of an array than creating two enumerators (the following comment section)

if ([[FileName pathextension]

Isequalto: @ "jpg"]) {

[File Addobject:filename];

}

}

For (nsstring *filename in file) {

NSLog (@ "%@", filename);

}

Nsdirectoryenumerator *direnum;

Direnum = [Manger enumeratoratpath:home];

//

//

NSString *filename;

while (filename = [Direnum nextobject]) {

if ([[[FileName pathextension] Isequalto: @ "jpg"]) {

[File Addobject:filename];

//            }

//        }

//

Nsenumerator *fileenum;

Fileenum = [File Objectenumerator];

//

while (filename = [Fileenum nextobject]) {

NSLog (@ "%@", filename);

//        }

}

return 0;

}



The output is as follows (partial):

2011-10-30 04:45:55.104 ocstudy[309:707] desktop/ not named _meitu_1.jpg

2011-10-30 04:45:55.105 ocstudy[309:707] desktop/ Software and Drivers /qq.app/contents/resources/guide1.jpg

2011-10-30 04:45:55.106 ocstudy[309:707] desktop/ Software and Drivers /qq.app/contents/resources/guide2.jpg

2011-10-30 04:45:55.106 ocstudy[309:707] desktop/ Software and Drivers /qq.app/contents/resources/guide3.jpg

2011-10-30 04:45:55.107 ocstudy[309:707] desktop/ Software and Drivers /qq.app/contents/resources/guide4.jpg

2011-10-30 04:45:55.107 ocstudy[309:707] desktop/ Software and Drivers /qq.app/contents/resources/guide5.jpg

2011-10-30 04:45:55.108 ocstudy[309:707] library/application support/iphone simulator/user/media/photos/thumbs/ F00/gktl.jpg

2011-10-30 04:45:55.108 ocstudy[309:707] library/application support/iphone simulator/user/media/photos/thumbs/ F00/ydff.jpg

2011-10-30 04:45:55.109 ocstudy[309:707] library/application support/iphone simulator/user/media/photos/thumbs/ F01/ajfw.jpg

2011-10-30 04:45:55.109 ocstudy[309:707] library/application support/iphone simulator/user/media/photos/thumbs/ F02/pxmw.jpg

2011-10-30 04:45:55.110 ocstudy[309:707] library/application support/iphone simulator/user/media/photos/thumbs/ F02/tbiy.jpg

2011-10-30 04:45:55.110 ocstudy[309:707] library/application support/iphone simulator/user/media/photos/thumbs/ F05/jijv.jpg

2011-10-30 04:45:55.111 ocstudy[309:707] library/application support/iphone simulator/user/media/photos/thumbs/ F05/muga.jpg

2011-10-30 04:45:55.111 ocstudy[309:707] library/application support/iphone simulator/user/media/photos/thumbs/ F05/nxon.jpg

2011-10-30 04:45:55.112 ocstudy[309:707] library/application support/iphone simulator/user/media/photos/thumbs/ F06/jrwj.jpg

2011-10-30 04:45:55.112 ocstudy[309:707] library/application support/iphone simulator/user/media/photos/thumbs/ F06/uqtd.jpg

2011-10-30 04:45:55.113 ocstudy[309:707] library/application support/iphone simulator/user/media/photos/thumbs/ F07/gwgq.jpg

2011-10-30 04:45:55.113 ocstudy[309:707] library/application support/iphone simulator/user/media/photos/thumbs/ F07/uspa.jpg

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.