2
我挽救了許多不同的圖像文件目錄以這樣的方式是否有文件目錄下的命令文件? IOS
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
int num = arc4random() % 100000000000000;
NSString* path = [documentsDirectory stringByAppendingPathComponent: [NSString stringWithFormat:@"%dtest.png", num]];
NSData* data = UIImagePNGRepresentation(image);
[data writeToFile:path atomically:YES];
然後,我用這種方式讀取文件:
NSString *stringPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
//NSString* FinalPath = [documentsDirectory stringByAppendingPathComponent: @"Images/"];
NSArray *filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:documentsDirectory error:&error];
for(int i=0;i<[filePathsArray count];i++)
{
NSString *strFilePath = [filePathsArray objectAtIndex:i];
if ([[strFilePath pathExtension] isEqualToString:@"jpg"] || [[strFilePath pathExtension] isEqualToString:@"png"] || [[strFilePath pathExtension] isEqualToString:@"PNG"])
{
NSString *imagePath = [[stringPath stringByAppendingFormat:@"/"] stringByAppendingFormat:strFilePath];
NSData *data = [NSData dataWithContentsOfFile:imagePath];
if(data)
{
@try {
NSString *nameOfGroup = [array objectAtIndex:i];
MWPhoto *photo;
photo= [MWPhoto photoWithFilePath:imagePath];
[finalPhotoArray addObject:photo];
}
@catch (NSException *exception) {
NSString *nameOfGroup = @"No description available for this sheet";
MWPhoto *photo;
photo= [MWPhoto photoWithFilePath:imagePath];
[finalPhotoArray addObject:photo];
}
}
}
的問題是圖像不正確排序,在我保存文件的順序中,但它們混在一起。有沒有辦法訂購它們?當我保存到文檔目錄時,這些文件是否混在一起?
爲什麼你需要爲了文件,如果你可以只排序其路徑的陣列?你知道,硬盤不是按字母順序排列的。 – CodaFi 2013-02-10 20:26:00
我需要它們,以便因爲我有字幕的陣列,並且每個標題是有序的,並且對應於一個圖像:例如1與1,2與2 ... – user2014474 2013-02-10 20:27:34
給您的文件名稱根據需要,你可以按字母順序排列,或以其他方式訂購。 – 2013-02-10 20:35:22