Created
April 4, 2013 14:57
-
-
Save demigod19892012/5311099 to your computer and use it in GitHub Desktop.
[iOS] List Files In A Directory And Subdirectories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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