英文:
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<PathItem> 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, "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());
}
}
For more details, please refer to here
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论