我试图在根级别枚举文件和文件夹
(/Users/Myname/Desktop or /Users/Myname/Documents),[enumarator nextobject] always gives nil value.
我该如何解决这个问题。
NSDirectoryEnumerator* enumerator = [[NSFileManager defaultManager] enumeratorAtPath:@"/Users/Myname/Desktop"];
NSString *content= [enumerator nextObject];//content always nil.
答案 0 :(得分:1)
试试这个:
NSFileManager *fileManager = [NSFileManager defaultManager];
NSDirectoryEnumerator * emuerator = [fileManager enumeratorAtPath:@"/usr/Myname/Desktop"];
NSString *filename; while ((filename = [emuerator
nextObject]))
{
NSLog (@"file! %@", filename);
}
OR
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSFileManager *manager = [[NSFileManager alloc] init];
NSDirectoryEnumerator *emuerator= [manager enumeratorAtPath: @"/usr/Myname/Desktop"];
for (NSString *filename in emuerator) {
// Do something with file
}
[manager release];