2012-02-23 63 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

相關問題