October 2013
Intermediate to advanced
1053 pages
28h 7m
English
You either want to enumerate folders within a folder or you want to enumerate the list of files inside a folder. The act of enumerating means that you simply want to find all the folders and/or files within another folder.
Use the contentsOfDirectoryAtPath:error: instance
method of the NSFileManager class as
shown here. In this example, we are enumerating all the files, folders,
and symlinks under our app’s bundle folder:
-(BOOL)application:(UIApplication*)applicationdidFinishLaunchingWithOptions:(NSDictionary*)launchOptions{NSFileManager*fileManager=[[NSFileManageralloc]init];NSString*bundleDir=[[NSBundlemainBundle]bundlePath];NSError*error=nil;NSArray*bundleContents=[fileManagercontentsOfDirectoryAtPath:bundleDirerror:&error];if([bundleContentscount]>0&&error==nil){NSLog(@"Contents of the app bundle = %@",bundleContents);}elseif([bundleContentscount]==0&&error==nil){NSLog(@"Call the police! The app bundle is empty.");}else{NSLog(@"An error happened = %@",error);}self.window=[[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]];// Override point for customization after application launch.self.window.backgroundColor=[UIColorwhiteColor];[self.windowmakeKeyAndVisible];returnYES;}
In some of your iOS apps, you may need to enumerate the contents of a folder. Let me give you an example, in case this need is a bit vague right now. Imagine that the user ...
Read now
Unlock full access