Object-c get all the files under the catalogue (including subdirectories)

Source: Internet
Author: User

Vector<string> Getallfilenamesindirectory () {

Ref TO:HTTP://STACKOVERFLOW.COM/QUESTIONS/5749488/ITERATING-THROUGH-FILES-IN-A-FOLDER-WITH-NESTED-FOLDERS-COCOA

Nsfilemanager *filemanager = [[[[Nsfilemanager alloc] init] autorelease];

Nsurl *directoryurl = [Nsurl urlwithstring:@ "Toolkitres/model"]; URL pointing to the directory want to browse

Nsarray *keys = [Nsarray Arraywithobject:nsurlisdirectorykey];

Nsdirectoryenumerator *enumerator = [FileManager

Enumeratoraturl:directoryurl

Includingpropertiesforkeys:keys

options:0

errorhandler:^ (Nsurl *url, Nserror *error) {

Handle the error.

Return YES If the enumeration should continue after the error.

return YES;

}];

Vector<string> fullpathlist;

For (Nsurl *url in enumerator) {

Nserror *error;

NSNumber *isdirectory = nil;

if (! [url getresourcevalue:&isdirectory forkey:nsurlisdirectorykey error:&error]) {

Handle error

}

else if (! [Isdirectory Boolvalue]) {

No error and it ' s not a directory; Do something with the file

NSString *str_ns=[url absolutestring];

NSLog (@ "%@", Str_ns);

String Fullpath=[str_ns cstringusingencoding:nsasciistringencoding];

Fullpathlist.push_back (FullPath);

}

}

return fullpathlist;

}

Object-c get all the files under the catalogue (including subdirectories)

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.