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

问题描述 投票:1回答:1

[我正在尝试找出一种在不知道确切文件名的情况下将文件从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 /”

我在所有方面都不怎么好。

powershell azure-powershell azure-data-lake
1个回答
1
投票

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

# Path: Specify the Data Lake Store path of the item to move
#Destination: Specify the Data Lake Store path to which to move the item
Move-AzDataLakeStoreItem -AccountName "ContosoADL" -Path "/Original/Path/File.txt" -Destination "/New/Path/RenamedFile.txt"

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

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

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.