Advertisement
ygamretuta

Objective C - Enumerate Dir Contents

Jul 11th, 2011
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // create an instance of the file manager
  2. fm = [NSFileManager defaultManager];
  3.  
  4. // get cwd
  5. path = [fm currentDirectoryPath];
  6.  
  7. // enum dir
  8. dirEnum = [fm enumeratorAtPath:path];
  9.  
  10. NSLog(@"Contents of %@", path);
  11.  
  12. while((path = [dirEnum nextObject]) != nil)
  13.     NSLog(@"%@", path);
  14.  
  15. // another way
  16. dirArray = [fm contentsOfDirectoryAtPath:[fm currentDirectoryPath]
  17.                                    error:NULL];
  18.  
  19. NSLog(@"Contents using contentsOfDirectoryAtPath:error:");
  20.  
  21. for (path in dirArray)
  22.     NSLog(@"%@", path);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement