如何在PowerShell中移动文件夹及其内容

san*_*san 1 powershell

我试图将一个文件夹及其内容从1个位置移动到另一个位置.该文件夹的名称是c:\ logfiles,它有子文件夹和文本文件,但我写的脚本,它只移动日志文件的内容,但我想将整个logfiles文件夹移动到一个新的位置

$current_logfiles = 'C:/LogFiles/*'
$new_logfiles = 'C:\My_Project\LogFiles\'

if (!(Test-Path -path $new_logfiles  )) {
New-Item $new_logfiles -type directory

Move-Item  -Path  $current_logfiles  -Destination $ $new_logfiles -Recurse -force
Run Code Online (Sandbox Code Playgroud)

}

arc*_*444 12

这是因为你拥有*,你告诉它要把一切都放在下面 C:\LogFiles.

这应该工作:

$current_logfiles = 'C:\LogFiles'
$new_logfiles = 'C:\My_Project\LogFiles'

if (!(Test-Path -path $new_logfiles)) {
  Move-Item -Path $current_logfiles -Destination $new_logfiles -force
}
Run Code Online (Sandbox Code Playgroud)