
animals/ -k.txt -d.jpg cat/ -r.txt -z.jpg tiger/ -a.jpg -p.pdf dog/ -n.txt -f.jpg -p.pdf
说我想对“动物”中的不是文件夹的每个文件运行一个进程。什么是最好的方法来遍历文件夹“animals”和所有的子文件夹访问每个文件?
谢谢。
解决方法 使用NSDirectoryEnumerator递归地枚举所需目录下的文件和目录,并要求它告诉您它是一个文件还是目录。以下是基于在 – [NSfileManager enumeratorAtURL:includePropertIEsForKeys:options:errorHandler:]的文档中列出的示例:NSfileManager *fileManager = [NSfileManager defaultManager];NSURL *directoryURL = … // URL pointing to the directory you want to browseNSArray *keys = [NSArray arrayWithObject:NSURlisDirectoryKey];NSDirectoryEnumerator *enumerator = [fileManager enumeratorAtURL:directoryURL includingPropertIEsForKeys:keys options:0 errorHandler:^(NSURL *url,NSError *error) { // Handle the error. // Return YES if the enumeration should continue after the error. return YES;}];for (NSURL *url in enumerator) { NSError *error; NSNumber *isDirectory = nil; if (! [url getResourceValue:&isDirectory forKey:NSURlisDirectoryKey error:&error]) { // handle error } else if (! [isDirectory boolValue]) { // No error and it’s not a directory; do something with the file }} 总结 以上是内存溢出为你收集整理的objective-c – 迭代具有嵌套文件夹的文件夹中的文件夹 – Cocoa全部内容,希望文章能够帮你解决objective-c – 迭代具有嵌套文件夹的文件夹中的文件夹 – Cocoa所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)