开发者

iPhone - check condition for folder

开发者 https://www.devze.com 2023-01-26 01:25 出处:网络
I have a tableView which lists the contents of the document directory. It contains files(开发者_Python百科jpg, png, mp4, pdf, sql, mp3,...) and folders(they even have subfolders too).

I have a tableView which lists the contents of the document directory. It contains files(开发者_Python百科jpg, png, mp4, pdf, sql, mp3,...) and folders(they even have subfolders too). Here is my screen shot.

iPhone - check condition for folder

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.

iPhone - check condition for folder

iPhone - check condition for folder

iPhone - check condition for folder

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);
   }

}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号