获取URL的所有文件夹

发布于 2024-10-31 02:07:18 字数 1234 浏览 0 评论 0原文

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

  • 读取所有文件夹
  • 获取文件夹内的文件 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/" )

任何人都可以帮助我找到答案了吗?我真的很困惑,谷歌没有找到好的解决方案或教程。

多谢, 马夫里克3。

Hi I'm trying to read all files from a given server. What I want to do:

  • Read all the folders
  • Get the file URLs inside the folders

I tried this to get the folders and filey of my server, but it returned me an array with the folders of my 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);

Log:

> 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/" )

Can anyone help me to find the answer? I'm really confused and Google didn't find a good solution or tutorial.

Thanks a lot,
mavrick3.

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

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

发布评论

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

评论(3

鲜肉鲜肉永远不皱 2024-11-07 02:07:18

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

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

You can't do this with NSFileManager. NSFileManager is intended to work with your file system (your device's file system) not with server.

you need to create a server side file which should give you folder/files url in xml file

も让我眼熟你 2024-11-07 02:07:18

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

You can not make use of NSFileManager to access the remote folders. This class is able to access the local directories only.
If your server supports FTP connection then you can make use of CFFTPStream.
CFFTPStream Reference

椵侞 2024-11-07 02:07:18

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

那为什么不创建一个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/

So if I understand correctly, you have the list of all the folders in the folder you need to read, but now you need specific files from each folder?

Then why don't you create a for-loop?

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

EDIT: If you mean you get the files from your Mac instead of the server you need, then you should change the line contentsOfDirectoryAtURL:directory to something like contentsOfDirectoryAtURL:@"http://localhost/myserver/.

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