如何使用Powershell -recursive在Azure Data Lake Store中移动文件?

时间:2019-10-30 09:50:18

标签: powershell azure-powershell azure-data-lake

我试图找出一种方法,将文件在ADLS gen1上从一个文件夹移动到另一个文件夹,而又不知道确切的文件名。

我想使用-recursive尝试使用Get-AzDataLakeStoreChildItem和Move-AzDataLakeStoreItem,但是由于某些原因,在AZ中不支持此操作。

我正在尝试这个

Get-AzDataLakeStoreChildItem -Account "my_acc" -Path "/Training/TestCopy/Source/" |
Where-Object {$_.lastwritetime -ge (Get-Date).AddDays(-7)} -OutVariable File | 
Move-AzDataLakeStoreItem -Account "my_acc" -Destination "/Training/TestCopy/Target/$File" -WhatIf

但是它仅给出: 如果发生以下情况,该怎么办:在目标“ / Training / TestCopy / Target”上执行“移动”操作。

我希望将文件从“ / Training / TestCopy / Source /”传输到“ / Training / TestCopy / Target /”

我在所有这些方面都不是很好。

1 个答案:

答案 0 :(得分:1)

根据我的理解,您希望将文件从一个文件夹移动到另一个文件夹。如果是这样,请使用命令

Connect-AzAccount

$account = Get-AzDataLakeStoreAccount -ResourceGroupName asS -Name testadls02

$sourcePath="/test"
#get the files in the source folder
$files =Get-AzDataLakeStoreChildItem -Account $account.Name -Path $sourcePath

$targetPath ="/test1"

Foreach($file in $files){

  $name = $file.Name

  Move-AzDataLakeStoreItem -Account $account.Name -Path $file.Path -Destination "$targetPath/$name"
}
Write-Host "the file in sourcePath folder"
Get-AzDataLakeStoreChildItem -Account $account.Name -Path $sourcePath
Write-Host "-----------------------"
Write-Host "the file in targetPath folder"
Get-AzDataLakeStoreChildItem -Account $account.Name -Path $targetPath

有关更多详细信息,请参阅https://docs.microsoft.com/en-us/powershell/module/az.datalakestore/move-azdatalakestoreitem?view=azps-2.8.0

../dist/configure && sudo make uninstall

enter image description here