2012-02-23 60 views
0
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存在不。从应用程序目录中检索文档

可能是什么问题?

回答

1

您正在枚举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]]; 
} 
+0

感谢lot..it工作.. – Shubhank 2012-02-23 12:13:51

+0

不能接受你的答案,直到3分钟.. – Shubhank 2012-02-23 12:14:13

相关问题