Skip to content

Instantly share code, notes, and snippets.

@Morse-Code
Created April 6, 2013 21:53
Show Gist options
  • Save Morse-Code/5327772 to your computer and use it in GitHub Desktop.
Save Morse-Code/5327772 to your computer and use it in GitHub Desktop.
List contents of directory and all sub-directories.
NSFileManager*fileMgr;
NSString*entry;
NSString*documentsDir;
NSDirectoryEnumerator*enumerator;
BOOL isDirectory;
// Create file manager
fileMgr =[NSFileManager defaultManager];
// Path to documents directory
documentsDir =[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
// Change to Documents directory[fileMgr changeCurrentDirectoryPath:documentsDir];
// Enumerator for docs directory
enumerator =[fileMgr enumeratorAtPath:documentsDir];
// Get each entry (file or folder)while((entry =[enumerator nextObject])!=nil){// File or directoryif([fileMgr fileExistsAtPath:entry isDirectory:&isDirectory]&& isDirectory)
NSLog (@"Directory - %@", entry);
else
NSLog (@" File - %@", entry);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment