【问题标题】:Get all folders of URL获取 URL 的所有文件夹
【发布时间】:2011-07-30 21:02:14
【问题描述】:

您好,我正在尝试从给定服务器读取所有文件。我想做什么:

  • 读取所有文件夹
  • 获取文件夹内的文件 URL

我尝试使用此方法获取服务器的文件夹和文件,但它返回给我一个包含 MacBook 文件夹的数组:

NSURL *directory = [NSURL URLWithString:@"linktoserver"];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error = nil;
self.contentList = [[NSArray alloc] initWithArray:[fileManager contentsOfDirectoryAtURL:directory includingPropertiesForKeys:[[NSArray alloc] initWithObjects:NSURLNameKey, nil] options:NSDirectoryEnumerationSkipsHiddenFiles error:&error]];
if (error != nil) {
    NSLog(@"ERROR: %@",[error localizedDescription]);
}
NSLog(@"%@",contentList);

日志:

> 2011-04-06 15:37:38.413 Bildergalerie[744:207] (
>     "file://localhost/Applications/",
>     "file://localhost/Benutzerhandbu%CC%88cher%20und%20Informationen",
>     "file://localhost/Cancel",
>     "file://localhost/Developer/",
>     "file://localhost/Library/",
>     "file://localhost/opt/",
>     "file://localhost/Shockwave%20Log",
>     "file://localhost/System/",
>     "file://localhost/Users/",
>     "file://localhost/usr/" )

谁能帮我找到答案?我真的很困惑,Google 没有找到好的解决方案或教程。

非常感谢, mavrick3.

【问题讨论】:

    标签: iphone objective-c nsfilemanager


    【解决方案1】:

    您不能使用 NSFileManager 访问远程文件夹。此类只能访问本地目录。
    如果您的服务器支持 FTP 连接,那么您可以使用 CFFTPStream。
    CFFTPStream Reference

    【讨论】:

      【解决方案2】:

      你不能用 NSFileManager 做到这一点。 NSFileManager 旨在与您的文件系统(您设备的文件系统)一起使用,而不是与服务器一起使用。

      您需要创建一个服务器端文件,该文件应在 xml 文件中为您提供文件夹/文件 url

      【讨论】:

        【解决方案3】:

        所以如果我理解正确的话,你有你需要阅读的文件夹中所有文件夹的列表,但现在你需要每个文件夹中的特定文件?

        那你为什么不创建一个for循环呢?

        for (int i = 0; i < [contentlist count]; i++
        {
            //do your trick to get the file in the folder
            //save it
        }
        

        编辑:如果您的意思是从您的 Mac 而不是您需要的服务器获取文件,那么您应该将contentsOfDirectoryAtURL:directory 行更改为contentsOfDirectoryAtURL:@"http://localhost/myserver/ 之类的内容。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2010-12-18
          • 2017-04-17
          • 1970-01-01
          • 2016-11-11
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多