Loop in your Home directory
I wanted to implement a method that will go through all my files in my home directory. I couldn’t believe how easy that was. I have done it in C before and it was really really hard! Thank God, cocoa does it with a few lines:
1 2 3 4 5 6 7 8 | NSString *path = [NSString stringWithFormat:@”%@/”,NSHomeDirectory()]; NSFileManager *manager = [NSFileManager defaultManager]; NSDirectoryEnumerator *dirEnum = [manager enumeratorAtPath:path]; NSString *file; while (file = [dirEnum nextObject]){ NSLog(@”%@”,file ); } |