Powershell 2 copy-item which creates a folder if doesn't exist

前端 未结 9 2507
余生分开走
余生分开走 2020-12-05 12:55
$from = \"\\\\something\\1 XLS\\2010_04_22\\*\"
$to =  \"c:\\out\\1 XLS\\2010_04_22\\\"
copy-item $from $to -Recurse 

This works if c:\\out\\

9条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-05 13:03

    In PowerShell 3 and above I use the Copy-Item with New-Item.

    copy-item -Path $file -Destination (new-item -type directory -force ("C:\Folder\sub\sub\" + $newSub)) -force -ea 0
    

    I haven't tried it in ver 2.

提交回复
热议问题