Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save demigod19892012/5311099 to your computer and use it in GitHub Desktop.
Save demigod19892012/5311099 to your computer and use it in GitHub Desktop.
[iOS] List Files In A Directory And Subdirectories
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 directory
if ([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