Reputation: 7
I have an app for iOS that uses Filesharing,i want to save the files of documents in a 'BOOK.plist',only save the filetype is .txt 's files.how an I save these files and display in a tableview?
Hope for you help
Upvotes: 0
Views: 442
Reputation: 7
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [paths objectAtIndex:0];
NSFileManager *manager = [NSFileManager defaultManager];
self.frlistName2 = [[manager contentsOfDirectoryAtPath:documentsDirectoryPath error:nil]pathsMatchingExtensions:[NSArray arrayWithObject:@"txt"]];
NSString *obj = @".txt";
frlisturls2 = [[NSMutableArray alloc] initWithObjects:nil];
NSString *temp;
NSMutableString *mp3Path = [[NSMutableArray alloc] init];
int j =0;
for(int i =0 ; i< [frlistName2 count]; i++)
{
mp3Path = [NSMutableString stringWithString:documentsDirectoryPath];
[mp3Path appendString:@"/"];
temp = [frlistName2 objectAtIndex:i];
if([temp hasSuffix :obj])
{
[mp3Path appendString: temp];
[frlisturls2 addObject: mp3Path];
j++;
}
[mp3Path release];
NSLog(@"frlisturls2 is%@:",frlisturls2);
}
Above code display the files from iTunes file-sharing,and save these files' url in a array
Upvotes: 0
Reputation: 1274
You don't need to store your txt files in a plist. You can save your documents in the documents directory of your application sandbox. You can get the path to the doc directory via this code:
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
documentFolderPath = [searchPaths objectAtIndex: 0];
http://forums.macrumors.com/showthread.php?t=1233731
The code examples used will be helpful when you want to display the directory in the tableView. Hope i could help.
Upvotes: 1