2011-06-20 144 views

回答

4

林不知道有關網格視圖的一部分。但這會幫助你列出圖像。

NSString *documents = [@"~/Documents/gallery" stringByExpandingTildeInPath]; 
    NSFileManager *fileManager = [NSFileManager defaultManager]; 
    NSDirectoryEnumerator *direnum = [fileManager enumeratorAtPath:documents]; 
    NSError *error; 
    NSString *tString; 
    while ((tString = [direnum nextObject])) 
    { 
     if ([tString hasSuffix:@".jpg"]) 
     { 
      NSString *fileAbsPath = [NSString stringWithFormat:@"%@/%@",documents,tString]; 
      //Do something with the file 
     } 
    } 
+0

謝謝你的回答。 – miniplayground

0

這是如何從特定文件夾獲取所有文件的。您可以用NSDocumentDirectory替換NSCachesDirectory

- (NSArray *)getAllFilesfromAFolder:(NSString *)folderName 
{ 
    NSString *stringPath = nil; 
    if(folderName) 
     stringPath = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)objectAtIndex:0]stringByAppendingPathComponent:folderName]; 
    else 
     stringPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)objectAtIndex:0]; 

    NSArray *filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:stringPath error:nil]; 
    return filePathsArray; 
} 
相關問題