Objective-c Traverse folder to view files

Source: Internet
Author: User

//
Main.m
Filesearchtest
//
Created by Zhang Leonardo on 11-10-31.
Copyright (c) 2011 __mycompanyname__. All rights reserved.

to discuss Via:www.renren.com/leonardozhang
//

#import <Foundation/Foundation.h>

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

@autoreleasepool {

Nsfilemanager *manager = [Nsfilemanager Defaultmanager];

If a relative relative path is converted to an absolute path

NSString *home = [@ "/users/tang/desktop/123" Stringbyexpandingtildeinpath];

NSLog (@ "Home:%@", home);

List directories under File path

Nsdirectoryenumerator *direnum = [manager enumeratoratpath:home];

Nsmutablearray *files = [Nsmutablearray arraywithcapacity:42];

NSString *filename;

while (filename = [Direnum nextobject]) {

[Files Addobject:filename];

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

[Files Addobject:filename];

//            }

}

Nsenumerator *fileenum;

Fileenum = [Files Objectenumerator];

For (ID filePath in fileenum) {

NSLog (@ "%@", FilePath);

}

while (filename = [Fileenum nextobject]) {

NSLog (@ "%@", filename);

//        }

}

return 0;

}

Objective-c Traverse folder to view files

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.