Powershell 将文件从文件夹复制到新文件夹

Powershell 将文件从文件夹复制到新文件夹,powershell,Powershell,我正在制作一个脚本来创建一个文件夹,并将所有文本文件从本地计算机上的指定文件夹复制到新文件夹。我有创建文件夹的权限,但我不知道如何将文件夹中的所有文本文件复制到我创建的新文件夹中 $destDir = Read-Host -Prompt 'Please enter the new folder name: ' # Check if the folder exist if not create it $dir = $destDir if(!(Test-Path -Path $dir )){

我正在制作一个脚本来创建一个文件夹,并将所有文本文件从本地计算机上的指定文件夹复制到新文件夹。我有创建文件夹的权限,但我不知道如何将文件夹中的所有文本文件复制到我创建的新文件夹中

$destDir = Read-Host -Prompt 'Please enter the new folder name: '

# Check if the folder exist if not create it 

$dir = $destDir
if(!(Test-Path -Path $dir )){
    New-Item -ItemType directory -Path $dir
    Write-Host "New folder created"
}
else
{
  Write-Host "Folder already exists"
}
# Check if the folder exist if not create it 

If (!(Test-Path $destDir)) {

   md $dir

}

          }
这将有助于:

Copy-Item -path $sourceDir\*.txt -Destination $destDir

您可以使用
Get ChildItem
筛选所需的文本文件,然后将其导入
Copy item