如何获取具有父DataLakeDirectoryClient类实例的子文件/目录列表

huangapple go评论86阅读模式
英文:

How to get list of child files/directories having parent DataLakeDirectoryClient class instance

问题

我必须扫描整个数据湖文件系统。有如下代码:

PagedIterable<PathItem> pItems = ((DataLakeFileSystemClient)prmParent).listPaths();
for( PathItem pItem : pItems ){
  if pItem.isDirectory() ){
    ((DataLakeFileSystemClient)prmParent).getDirectoryClient(pItem.getName());
  } else {
    ((DataLakeFileSystemClient)prmParent).getFileClient(pItem.getName());
  }
}

我可以获取顶层目录/文件。但是要深入进入目录,DataLakeDirectoryClient 类中应该有 listChild() 方法。但我没有找到类似的内容。有人知道在树结构中遍历的正确方法吗?

谢谢。 Sergiy

英文:

I have to scan whole data lake file system. Having code like:

PagedIterable&lt;PathItem&gt; pItems = ((DataLakeFileSystemClient)prmParent).listPaths();
for( PathItem pItem : pItems ){
  if pItem.isDirectory() ){
    ((DataLakeFileSystemClient)prmParent).getDirectoryClient(pItem.getName());
  } else {
    ((DataLakeFileSystemClient)prmParent).getFileClient(pItem.getName());
  }
}

I get top level dirs/files. But to drill down there must be method listChild() in DataLakeDirectoryClient class.
But i did not find anything similar.
Does anybody know what is the proper way to walk thru the tree?

Thanks. Sergiy

答案1

得分: 0

如果您想列出 Azure 数据湖 Gen2 文件系统中的所有路径,请参考以下代码:

 StorageSharedKeyCredential credential = new StorageSharedKeyCredential(accountName, accountKey);
String endpoint = String.format(Locale.ROOT, "https://%s.dfs.core.windows.net", accountName);
DataLakeServiceClient storageClient = new DataLakeServiceClientBuilder()
        .endpoint(endpoint)
        .credential(credential)
        .buildClient();

DataLakeFileSystemClient dataLakeFileSystemClient = storageClient.getFileSystemClient("test");
ListPathsOptions options = new ListPathsOptions();
options.setRecursive(true);
PagedIterable<PathItem> pItems = dataLakeFileSystemClient.listPaths(options,null);

for( PathItem pItem : pItems ){
    if(pItem.isDirectory()) {
        System.out.println("The directory: " + pItem.getName());
    }else{
        System.out.println("The file : " + pItem.getName());
    }
}

更多详情,请参考这里

英文:

If you want to list all path in Azure data lake gen2 file system, please refer to the following code

 StorageSharedKeyCredential credential = new StorageSharedKeyCredential(accountName, accountKey);
        String endpoint = String.format(Locale.ROOT, &quot;https://%s.dfs.core.windows.net&quot;, accountName);
        DataLakeServiceClient storageClient = new DataLakeServiceClientBuilder()
                .endpoint(endpoint)
                .credential(credential)
                .buildClient();

        DataLakeFileSystemClient dataLakeFileSystemClient = storageClient.getFileSystemClient(&quot;test&quot;);
        ListPathsOptions options = new ListPathsOptions();
        options.setRecursive(true);
        PagedIterable&lt;PathItem&gt; pItems = dataLakeFileSystemClient.listPaths(options,null);

        for( PathItem pItem : pItems ){
            if(pItem.isDirectory()) {
                System.out.println(&quot;The directory: &quot; +pItem.getName());
            }else{
                System.out.println(&quot;The file : &quot; +pItem.getName());
            }
        }

如何获取具有父DataLakeDirectoryClient类实例的子文件/目录列表

For more details, please refer to here

huangapple
  • 本文由 发表于 2020年10月23日 02:12:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/64488196.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定