List of files in a directory and subdirectories
NSFileManager *fileMgr;
NSString *entry;
NSString *documentsDir;
NSDirectoryEnumerator *enumerator;
BOOL isDirectory; // creo il file manager
fileMgr = [NSFileManager defaultManager]; // localizzo la cartella documenti
documentsDir = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
// sposto il file manager nella cartella
documenti =[fileMgr changeCurrentDirectoryPath:documentsDir]; // enumero i documenti contenuti
enumerator = [fileMgr enumeratorAtPath:documentsDir];
// scorro ogni elemento
while ((entry = [enumerator nextObject]) != nil){ // file o cartella
if ([fileMgr fileExistsAtPath:entry isDirectory:&isDirectory] && isDirectory)
NSLog (@"Cartella - %@", entry);
else NSLog (@" File - %@", entry);
}
Written by DiegoCaridei
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Xcode
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#