2017-03-17 56 views
-1

我有文件夾主有許多子文件夾(AA,AB,AC,...,ZZ),每個子文件夾有5個文件夾(1,2,3,4,5)哪一個可以有.csv文件。Powershell文件複製和重命名基於路徑

我需要編寫一個腳本,將每個.csv文件複製到輸出文件夾中,並根據發現的子文件夾(AA.csv,BB.csv等)對其進行重命名,獲取csv文件列表並創建輸出文件夾。

New-Item C:\Output -force 
$FileExtension = ".csv" 
$Dir = get-childitem $FolderPath -recurse 
$List = $Dir | where {$_.extension -eq $FileExtension} 
$List | format-table Name 

回答

1

我想你可以有多個CSV文件到您的迪爾斯,我提出這個解決方案

$Pathsource="C:\Temp\" # let the '\' 
$Pathdestination="C:\Temp2\" 

#remove -whatif if its ok 
Get-ChildItem $Pathsource -Recurse -Filter "*.csv" | %{Copy-Item $_.FullName ($Pathdestination + $_.FullName.Replace($Pathsource , '').Replace('\', '_')) -WhatIf}