【问题标题】:how to chech image is existing in the folder [duplicate]如何检查文件夹中是否存在图像[重复]
【发布时间】:2011-10-04 06:30:05
【问题描述】:
可能重复:
What's a quick way to test to see a file exists?
我是 iPhone 开发的新手。我将图像保存在“文档”文件夹中。下面显示了用于此的代码
NSString *fullPath=[[NSString stringWithFormat:@"Documents/%@",limgName] retain];
NSString *mpngPath = [NSHomeDirectory() stringByAppendingPathComponent:fullPath];
NSLog(@"saving path %@",mpngPath);
[myImgdata writeToFile:mpngPath atomically:YES];
我的目标是下次我想检查此图像是否存在于文件夹中。如何检查此路径是否存在。
【问题讨论】:
标签:
iphone
objective-c
ios4
【解决方案1】:
您必须以相同的方式获取mpngPath,然后使用NSFileManager 检查文件是否存在。
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:mpngPath];
if ( fileExists ) {
/* The image exists. Handle appropriately */
}
【解决方案2】:
您是否这样做过:
CFShow([[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingString:@"/Documents"]]);