iOS DropboxSDK,获取远程子目录和内容

发布于 2024-10-24 20:25:00 字数 700 浏览 2 评论 0原文

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

远程端:

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

上传文件和目录/以及带有文件的子目录不是问题。当涉及到将子目录及其内容从保管箱传输到设备时,我简直犯了大错。

put

-(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)];
    }
}

get

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

我不知道如何迭代远程端的子目录。

I have a remote directory with several subdirectories and files in them on Dropbox.

remote side:

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

Uploading the files and directories / and subdirectories with files is not a problem. I am having a brain fart when it comes to getting the subdirectories and their contents from dropbox to the device.

put

-(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)];
    }
}

get

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

I am not sure how to iterate through the subdirectories on the remote side.

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

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

发布评论

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

评论(1

不知所踪 2024-10-31 20:25:00

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

要限制并行提取的数量,请对所有 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
}

First load the directory metadata, then load the files that it references.

To limit the number of parallel fetches, use a NSOperationQueue for all of the loadMetadata and loadFile calls to limit the number of parallel fetches. And to avoid redundant file downloads, remember the downloaded metadata in a 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
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文