iPhone - 检查文件夹的状况

发布于 2024-10-03 12:56:14 字数 977 浏览 0 评论 0原文

我有一个 tableView,其中列出了文档目录的内容。它包含文件(jpg、png、mp4、pdf、sql、mp3...)和文件夹(它们甚至还有子文件夹)。 这是我的屏幕截图。

alt text

其中列表中的“SQLTutorial”是一个文件夹。

然后我有一个detailViewController,它在tableView 中选择时打开文件。 这是我的屏幕截图。

替代文本

替代文本

alt text

问题是我不知道如何检查文件夹的条件并使其列出子文件夹下一个视图。我正在检查如下图片和视频的条件,它有效。

图像的条件

if ([detailedViewController.strType isEqualToString:@"jpg"]) {
}

视频的条件

if ([detailedViewController.strType isEqualToString:@"mp4"]) {
}

pdf 的条件

if ([detailedViewController.strType isEqualToString:@"pdf"]) {
}

我正在检查这样的文件夹的条件

if ([detailedViewController.strType isEqualToString:@""]) {
}

,但它不起作用。

知道如何让它发挥作用吗?提前致谢..

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.

alt text

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.

alt text

alt text

alt text

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..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回忆那么伤 2024-10-10 12:56:14

我认为您可以按如下方式检查文件夹是否存在

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

}

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

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文