[英]copy all files and folders from one drive to another drive using DOS (command prompt)
[英]Using PowerShell v5, search for specific folder(s) copy those folders/files, AND the paths to another drive
我是PowerShell的新手。 花了幾天時間試圖做到這一點,認為我已經很接近了,但是需要專家向我展示最后一步。
使用PowerShell v5,需要搜索與特定名稱匹配的文件夾,然后將這些文件夾及其文件以及文件夾的路徑復制到另一個驅動器。
現在腳本:
Get-ChildItem s:\ -Filter (Read-Host -Prompt "Enter") -Recurse -ErrorAction SilentlyContinue -Force |
Select-Object FullName | ForEach-Object {Copy-Item -Path $_.FullName -Destination 'C:\Robotics\AA\ConfigFiles\Automation Anywhere Files\Automation Anywhere\My Tasks\' -recurse -Force}
這將搜索文件夾,返回結果,然后將文件夾和內容復制到目標位置。
問題是,我實際上需要將源路徑附加到我的目標路徑。 來源是可變數量的文件夾。
有什么建議么?
-Directory
Copy-Item
接受來自管道的輸入,不需要ForEach-Object
。 -replace
基於RegEx,並且要求路徑S:\\
中的反斜杠由另一個反斜杠S:\\\\
進行轉義。 $DestBase = 'C:\Robotics\AA\ConfigFiles\Automation Anywhere Files\Automation Anywhere\My Tasks\'
$Search = Read-Host -Prompt "Enter folder:"
Get-ChildItem -Path S:\ -Filter $Search -Directory -Recurse -ErrorAction SilentlyContinue -Force |
Copy-Item -Destination {$($_.Fullname) -replace 'S:\\',"$DestBase"} -Recurse -Force -Whatif
如果輸出看起來正常,請在最后一行刪除-WhatIf
參數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.