[英]retrieving documents from applications directory
NSURL* suppurl = [manager URLForDirectory:NSApplicationSupportDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil];
NSString *path = [suppurl path];
NSLog(@" Path %@",path);
NSString* myfolder = [path stringByAppendingPathComponent:@"MyFolder"];
NSDirectoryEnumerator* myFolderDir = [manager enumeratorAtPath:myfolder];
for (NSString* file in myFolderDir)
{
NSLog(@" file %@",file);
NSString *getImagePath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",file]];
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:getImagePath];
NSLog(@" image path %@",getImagePath);
if (exists)
{
NSLog(@" exists");
}
第一个NSLog(@" file %@",file);
成功记录文件名...但BOOL不存在。
可能是什么问题呢?
您正在枚举myFolderDir
文件,但随后尝试验证path
是否存在同名文件。 用。。。来代替:
NSString *getImagePath = [myFolderDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",file]];
另外,请注意,您不需要这样做:
[NSString stringWithFormat:@"%@",file]
.. file
已经是NSString
。
如果您要枚举该文件夹中的图像,请考虑测试文件扩展名:
if ([[file pathExtension] isEqualToString: @"jpg"]) {
// load the image
[self loadImage: [myFolderDir stringByAppendingPathComponent:file]];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.