获取 Dropbox 中的条目数

Get number of entries in Dropbox

我正在制作一个将文件夹上传到 Dropbox 的脚本。因此,为了验证文件是否已上传,我需要在 Dropbox 中获取上传前后的目录数。

我如何使用 Java 执行此操作。

提前致谢

重要提示:请注意,此代码使用 Dropbox API v1 Java SDK, which is deprecated. You should use the Dropbox API v2 Java SDK 代替。

使用getMetadataWithChildren it will return a DbxEntry.WithChildren object. This object contain a field children of type List witch as a size method.

dbxClient.getMetadataWithChildren(path).children.size();

注意,getMetadataWithChildren 可以 return null 并且 children 也可以 null

如果要验证上传的文件,应该检查上传本身的响应。它将直接指示上传是否成功。如果成功,它将 return 上传的文件元数据。如果没有,它将引发错误。有 an example of uploading with the Dropbox API v2 Java SDK here.

如果您确实想通过使用 Dropbox API v2 Java SDK 列出文件夹的内容,您应该使用 listFolder and listFolderContinue. There's an example of that here.