Powershell-Azure Data Lake存储中的递归
有人知道如何列出data lake store和子目录中目录中的每个文件吗?显然,Powershell-Azure Data Lake存储中的递归,powershell,azure,recursion,azure-data-lake,data-lake,Powershell,Azure,Recursion,Azure Data Lake,Data Lake,有人知道如何列出data lake store和子目录中目录中的每个文件吗?显然,-recursive指令不像在正常环境中那样工作 我需要在Azure Data Lake Store中运行此脚本(在我的计算机中正常运行) 我正在使用命令getazurermdatalakestorechilditem,其中显然不支持-recursive 有人能帮我吗 谢谢,这里有一个递归的方法(注意:它的伸缩性不好,因为它对每个子目录都进行了API调用,并且没有并行化,因为它将所有文件存储到内存中) 我采取了另一
-recursive
指令不像在正常环境中那样工作
我需要在Azure Data Lake Store中运行此脚本(在我的计算机中正常运行)
我正在使用命令getazurermdatalakestorechilditem
,其中显然不支持-recursive
有人能帮我吗
谢谢,这里有一个递归的方法(注意:它的伸缩性不好,因为它对每个子目录都进行了API调用,并且没有并行化,因为它将所有文件存储到内存中)
我采取了另一种方法,但答案是做我自己的递归函数
function Get-DataLakeStoreChildItemRecursive ([string]$path, [string]$account, [string]$quarantine) {
$dirs = Get-AzureRmDataLakeStoreChildItem -Account $account -Path $path
foreach ($dir in $dirs) {
switch ($dir.Type) {
"FILE" {
if(($path + $dir.Name) -match "^/adls-dev/raw/amp/(.+/)*(amp.+)\.(.+)$") {
}
else {
$to = $quarantine + ("{0:yyyyMMddHHmmss}-" -f (get-date)) + $dir.Name
Move-AzureRmDataLakeStoreItem -AccountName $account -Path ($path + $dir.Name) -Destination $to
}
}
"DIRECTORY" {
$q = ($quarantine + $dir.Name + '/')
$test = Test-AzureRmDataLakeStoreItem -AccountName $account -Path $q
if($test -eq $False) {
New-AzureRmDataLakeStoreItem -AccountName $account -Path $q -Folder
}
Get-DataLakeStoreChildItemRecursive ($path + $dir.Name + '/') $account $q
}
}
}
}
Get-DataLakeStoreChildItemRecursive "/adls-dev/raw/amp/" "asdf" "/adls-dev/quarantine/"
function Get-DataLakeStoreChildItemRecursive ([hashtable] $Params) {
$AllFiles = New-Object Collections.Generic.List[Microsoft.Azure.Commands.DataLakeStore.Models.DataLakeStoreItem];
recurseDataLakeStoreChildItem -AllFiles $AllFiles -Params $Params
$AllFiles
}
function recurseDataLakeStoreChildItem ([System.Collections.ICollection] $AllFiles, [hashtable] $Params) {
$ChildItems = Get-AzureRmDataLakeStoreChildItem @Params;
$Path = $Params["Path"];
foreach ($ChildItem in $ChildItems) {
switch ($ChildItem.Type) {
"FILE" {
$AllFiles.Add($ChildItem);
}
"DIRECTORY" {
$Params.Remove("Path");
$Params.Add("Path", $Path + "/" + $ChildItem.Name);
recurseDataLakeStoreChildItem -AllFiles $AllFiles -Params $Params;
}
}
}
}
Get-DataLakeStoreChildItemRecursive -Params @{ 'Path' = '/Samples'; 'Account' = 'youradlsaccount' }
function Get-DataLakeStoreChildItemRecursive ([string]$path, [string]$account, [string]$quarantine) {
$dirs = Get-AzureRmDataLakeStoreChildItem -Account $account -Path $path
foreach ($dir in $dirs) {
switch ($dir.Type) {
"FILE" {
if(($path + $dir.Name) -match "^/adls-dev/raw/amp/(.+/)*(amp.+)\.(.+)$") {
}
else {
$to = $quarantine + ("{0:yyyyMMddHHmmss}-" -f (get-date)) + $dir.Name
Move-AzureRmDataLakeStoreItem -AccountName $account -Path ($path + $dir.Name) -Destination $to
}
}
"DIRECTORY" {
$q = ($quarantine + $dir.Name + '/')
$test = Test-AzureRmDataLakeStoreItem -AccountName $account -Path $q
if($test -eq $False) {
New-AzureRmDataLakeStoreItem -AccountName $account -Path $q -Folder
}
Get-DataLakeStoreChildItemRecursive ($path + $dir.Name + '/') $account $q
}
}
}
}
Get-DataLakeStoreChildItemRecursive "/adls-dev/raw/amp/" "asdf" "/adls-dev/quarantine/"