2017-04-09 203 views
1

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

$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 

} 

      } 
+0

你可以使用'的Get- ChildItem'过滤你想要的文本文件,然后将其转换为'Copy-item' – BenH

+1

[像这样?](http://stackoverflow.com/questions/16004984/powershell-command-to-copy-only-text-files ) –

回答

1

这样做:

Copy-Item -path $sourceDir\*.txt -Destination $destDir 
相关问题