获取mac上所有文件

获取mac上所有文件

by 伍雪颖

#import <Cocoa/Cocoa.h>

int main(int argc, const char * argv[]) {
   
NSMutableArray *directoryDict = [NSMutableArray new];
    [directoryDict
addObject:@{@"url":[NSURL URLWithString:NSHomeDirectory()],
                              
@"id":@(0)}];
   
NSInteger Id = 1;
   
while (directoryDict.count != 0) {
       
NSDictionary *info = [directoryDict firstObject];
        [directoryDict
removeObject:info];
       
NSDirectoryEnumerator *directoryEnumerator = [[NSFileManager defaultManager]
                                                     
enumeratorAtURL:info[@"url"]
                                                     
includingPropertiesForKeys:nil
                                                      options:NSDirectoryEnumerationSkipsHiddenFiles
                                                      errorHandler:nil];
       
for(NSURL *fileURL in directoryEnumerator) {
            [directoryEnumerator
skipDescendants];
           
NSLog(@"%@",fileURL);
           
NSNumber *isDirectory=nil;
           
NSError *error=nil;
            [fileURL getResourceValue:&isDirectory
                              forKey:NSURLIsDirectoryKey
                              error:&error];
            if([isDirectory isEqualTo:@YES]) {
                [directoryDict
addObject:@{@"url":fileURL,
                                          
@"id":@(Id)}];
            }
            Id++;
        }
        info =
nil;
    }
   
return NSApplicationMain(argc, argv);
}

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。