2011-04-06 124 views
1

嗨我试图从给定的服务器读取所有文件。我想做什么:获取URL的所有文件夹

  • 阅读所有的文件夹
  • 获取

我想这让我的服务器的文件夹和法利的文件夹里面的文件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/") 

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

非常感谢, mavrick3。

回答

0

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

0

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

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

1

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

你需要创建一个服务器端的文件,它应该给你的xml文件夹/文件URL

相关问题