Powershell: рекурсивное перемещение файлов

Я пытаюсь скопировать все выходные файлы сборки и папки вмусорное ведро папка (OutputDir / Bin) за исключением некоторых файлов, которые остаются вOutputDir,мусорное ведро папка никогда не будет удалена.

Начальное состояние:

Output
   config.log4net
   file1.txt
   file2.txt
   file3.dll
   ProjectXXX.exe
   en
      foo.txt
   fr
      foo.txt
   de
      foo.txt

Цель:

Output
   Bin
      file1.txt
      file2.txt
      file3.dll
      en
         foo.txt
      fr
         foo.txt
      de
         foo.txt
   config.log4net
   ProjectXXX.exe

Моя первая попытка:

$binaries = $args[0]
$binFolderName = "bin"
$binFolderPath = Join-Path $binaries $binFolderName

New-Item $binFolderPath -ItemType Directory

Get-Childitem -Path $binaries | ? {$_.Name -notlike "ProjectXXX.*" -and $_.Name -ne "config.log4net" -and $_.Name -ne $binFolderName }  | Move-Item -Destination $binFolderPath

Это не работает, потому чтоMove-Item не умеет перезаписывать папки.

Моя вторая попытка:

function MoveItemsInDirectory {
    param([Parameter(Mandatory=$true, Position=0)][System.String]$SourceDirectoryPath,
          [Parameter(Mandatory=$true, Position=1)][System.String]$DestinationDirectoryPath,
          [Parameter(Mandatory=$false, Position=2)][System.Array]$ExcludeFiles)
    Get-ChildItem -Path $SourceDirectoryPath -Exclude $ExcludeFiles | %{
        if ($_ -is [System.IO.FileInfo]) {
            $newFilePath = Join-Path $DestinationDirectoryPath $_.Name
            xcopy $_.FullName $newFilePath /Y
            Remove-Item $_ -Force -Confirm:$false
        }
        else
        {
            $folderName = $_.Name
            $folderPath = Join-Path $DestinationDirectoryPath $folderName

            MoveItemsInDirectory -SourceDirectoryPath $_.FullName -DestinationDirectoryPath $folderPath -ExcludeFiles $ExcludeFiles
            Remove-Item $_ -Force -Confirm:$false
        }
    }
}

$binaries = $args[0]
$binFolderName = "bin"
$binFolderPath = Join-Path $binaries $binFolderName
$excludeFiles = @("ProjectXXX.*", "config.log4net", $binFolderName)

MoveItemsInDirectory $binaries $binFolderPath $excludeFiles

Есть ли альтернативный способ рекурсивного перемещения файлов более простым способом с помощью PowerShell?

Ответы на вопрос(2)

Ваш ответ на вопрос