I have a tableView which lists the contents of the document directory. It contains files(jpg, png, mp4, pdf, sql, mp3,...) and folders(they even have subfolders too). Here is my screen shot.
where "SQLTutorial" in the list is a folder.
Then I have a detailViewController which opens the file when selected in the tableView. Here is my screen shot.
The problem is I have no idea how to check the condition for a folder and make it list the subfolders in the next view. I am checking the conditions for pictures and videos like the following and it works.
Condition for a image
if ([detailedViewController.strType isEqualToString:@"jpg"]) {
}
Condition for a video
if ([detailedViewController.strType isEqualToString:@"mp4"]) {
}
Condition for a pdf
if ([detailedViewController.strType isEqualToString:@"pdf"]) {
}
I am checking the condition for a folder like this
if ([detailedViewController.strType isEqualToString:@""]) {
}
But it does'nt works.
Any idea how to make it work? Thanks in advance..
I think you can check existance of folder as follows
NSArray *contentsArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:NULL];
if(contentsArray==nil)
{
NSLog(@"This directory doesn't exist");
}
else if(contentsArray.count==0)
{
NSLog(@"Directory exists but doesn't have any content i.e. files or folders");
}
else if(contentsArray.count>0)
{
for (NSString *path in contentsArray)
{
NSLog(@"Content Path :%@",path);
}
}