2012-02-23 5 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 인을. lot..it 근무

if ([[file pathExtension] isEqualToString: @"jpg"]) { 
    // load the image 
    [self loadImage: [myFolderDir stringByAppendingPathComponent:file]]; 
} 
+0

덕분에 ... – Shubhank

+0

3 분까지 답변을 받아 들일 수 없다 .. : 경우

당신은 파일 확장자를 테스트 고려, 해당 폴더에 이미지를 열거하려는 – Shubhank

관련 문제