1

我在 Dropbox 上有一个包含多个子目录和文件的远程目录。

远端:

-Mobile Profiles *(root)*
-- Custom Profiles
--- Profile1
--- Profile2
--- Profile3

上传文件和目录/以及带有文件的子目录不是问题。在将子目录及其内容从 Dropbox 获取到设备时,我脑子里一片空白。

-(void)backupCustomProfiles {
    for ( NSString *file in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:MP_CUSTOM error:&error] ) {
        [self.restClient uploadFile:file toPath:@"/Mobile Profiles/Custom Profiles/" fromPath:EasyStrings(MP_CUSTOM,file)];
    }
}

得到

-(void)restoreCustomProfiles {
    for ( ) {
        /* ? */
    }
}

我不确定如何遍历远程端的子目录。

4

1 回答 1

5

首先加载目录元数据,然后加载它引用的文件。

要限制并行获取的数量,请对所有 loadMetadata 和 loadFile 调用使用 NSOperationQueue 来限制并行获取的数量。并且为了避免多余的文件下载,请记住 plist 中下载的元数据。

- (void) restoreCustomProfiles
{
    [self.client loadMetadata:@"/Mobile Profiles/Custom Profiles" withHash:hash];
}

- (void) restClient:(DBRestClient*)client loadedMetadata:(DBMetadata*)metadata
{
    for (DBMetadata* child in metadata.contents) {
        NSString *path = [child.path lowercaseString];

        if (child.isDirectory) {
            [client loadMetadata:child.path withHash:hash];
        } else {
            [client loadFile:pathToDownload intoPath:[
                                self.directory stringByAppendingString:path]];
        }
    }
}

- (void) restClient:(DBRestClient*)client loadedFile:(NSString*)destPath
{
    // successfully downloaded a file to destPath
}
于 2011-03-22T05:12:31.063 回答