3

有人知道如何列出数据湖存储和子目录中目录中的每个文件吗?显然该-recursive指令不像在正常环境中那样工作

我需要在 Azure Data Lake Store 中运行此脚本(在我的计算机上正常运行)

$Quarentine = "C:\PSTest\QUARENTINE"

$validate = "C:\PSTest\Files"

get-childitem $validate -rec -af | Where-Object {$_.FullName -notmatch "^C:\\PSTest\\Files\\(.+\\)*(XX.+)\.(.+)$"} | 
move-item -destination {"C:\PSTest\QUARENTINE\"+ $_.BaseName +("{0:yyyyMMddHHmmss}" -f (get-date)) + $_.Extension}

我正在使用Get-AzureRmDataLakeStoreChildItem显然-recursive不支持的命令。

有人能帮助我吗?

谢谢

4

2 回答 2

3

这是一种递归方式(警告:它不能很好地扩展,因为它对每个子目录进行 API 调用并且没有并行化,并且因为它将所有文件存储到内存中)。

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' }
于 2016-12-22T08:15:05.393 回答
0

我采取了另一种方法,但是答案是做我自己的递归函数

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/"
于 2016-12-22T23:27:59.367 回答