2017-04-09 202 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 
相關問題