我正在将音频文件列表存储到我的文档目录中,然后获取它们。
它给了我一个音频文件列表,同时它给了我一个带有 name 的文件@".DS_Store"
。在获取内容时,我想保留此文档目录文件。
@".DS_Store"
除了从数组中删除它或应用检查之外,有什么方法可以在获取音频列表时摆脱它。
这究竟是什么原因。?
#pragma mark - Saving Audio in Document Directory
-(void)saveAudioinDocumentDirectory:(ASIHTTPRequest *)theRequest
{
/*save the Audio file in Document Directory */
NSFileManager *fileManager=[NSFileManager defaultManager];
NSLog(@"GOT THE SIZe OF AUDIO %d",[[theRequest responseData] length]);
NSLog(@"AUDIO ID IS %@",[[theRequest userInfo] valueForKey:@"audioIndex"]);
/*Get the Path to Application Documents Directory*/
NSArray *docDir=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
/*append the neccessary file extension */
NSString *filepathStr=[NSString stringWithFormat:@"/%@/%@.mp3",docDir,[NSString stringWithFormat:@"%@",[[theRequest userInfo] valueForKey:@"audioIndex"]]];
/*Check if my crrent file exists in the Documents Directory*/
if(![fileManager fileExistsAtPath:filepathStr])
{
/* file doesnt exists */
/*create a NSdata of File*/
NSData *data=[NSData dataWithData:[theRequest responseData]];
NSLog(@"%@",filepathStr);
if ([data length] >0 ){
/*write the File at the Location in Documents Directory */
[data writeToFile:filepathStr atomically:YES];
NSLog(@"Successfully saved the file to %@", filepathStr);
}
else if([data length] == 0)
{
NSLog(@"Nothing was downloaded.");
}
}
/*After saving fetch the path til documents Directory*/
NSArray *folders = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
/*Get the Path for Files */
NSString *s=[folders objectAtIndex:0];
/*Fetch the list of Files stored in Documents Directory*/
NSArray *contents = [fileManager contentsOfDirectoryAtPath:s error:NULL];
NSLog(@"TOTAL NUMBER OF AUDIO FILES %d %@",[contents count],[contents objectAtIndex:0]);
if([Audiolistforstr isEqualToString:@"AudioListForIntro"])
{
// NSLog(@"Audiolistforstr@"IntroThirdRow" in reading audio from document Intro IS %@",Audiolistforstr);
/*Intro*/
[AudioListArrForIntro removeAllObjects];
[AudioListArrForIntro addObjectsFromArray:contents];
if([AudioListArrForIntro containsObject:@".DS_Store"])
{
[AudioListArrForIntro removeObject:@".DS_Store"];
}
NSLog(@"FINAL LIST %@",AudioListArrForIntro);
}
else if([Audiolistforstr isEqualToString:@"AudioListForCredits"])
{
// NSLog(@"Audiolistforstr@"IntroThirdRow" in reading audio from document credit IS %@",Audiolistforstr);
/*credits*/
[AudioListArrForCredits removeAllObjects];
[AudioListArrForCredits addObjectsFromArray:contents];
if([AudioListArrForCredits containsObject:@".DS_Store"])
{
[AudioListArrForCredits removeObject:@".DS_Store"];
}
NSLog(@"FINAL LIST %@",AudioListArrForCredits);
}
/* Did we find anything? */
if([Audiolistforstr isEqualToString:@"AudioListForIntro"])
{
// NSLog(@"Audiolistforstr@"IntroThirdRow" in reading audio fromRELOADNG TABLE Intro IS %@",Audiolistforstr);
/*Intro*/
if ([AudioListArrForIntro count] == 0)
{
}
else
{
UIView *vw=(UIView *)[self.view viewWithTag:ViewAddAudioIntroTag];
[(UITableView *)[vw viewWithTag:tblIntroAudioListTag] reloadData];
}
}
else if([Audiolistforstr isEqualToString:@"AudioListForCredits"])
{
// NSLog(@"Audiolistforstr@"IntroThirdRow" in reading audio fromRELOADNG TABLE Intro IS %@",Audiolistforstr);
/*Credits*/
if ([AudioListArrForCredits count] == 0)
{
}
else
{
/*AudioListForCredits*/
UIView *vw=(UIView *)[self.view viewWithTag:ViewAddAudioCreditsTag];
[(UITableView *)[vw viewWithTag:tblCreditsAudioListTag] reloadData];
}
}
}
任何帮助,将不胜感激。
谢谢维卡斯