2011-04-06 130 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

相關問題