Ignore hidden files and directories with obj-c

北城以北 提交于 2019-12-30 08:51:07

问题


How can I execute hidden directory and files programmatically?

i.e: .DS_Store

I want to execute all the hidden files and directories which start with the "."

Thank you for your help in advance


回答1:


Use NSFileManager with NSDirectoryEnumerationSkipsHiddenFiles.

For example:

NSFileManager *fileManager = [NSFileManager defaultManager];

NSArray *theFiles =  [fileManager contentsOfDirectoryAtURL:[NSURL fileURLWithPath:@"/Users/Anne/Desktop/"]
                                includingPropertiesForKeys:[NSArray arrayWithObject:NSURLNameKey]
                                                   options:NSDirectoryEnumerationSkipsHiddenFiles
                                                     error:nil];

NSLog(@"%@",theFiles);


来源:https://stackoverflow.com/questions/8053820/ignore-hidden-files-and-directories-with-obj-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!