Mic*_*Mit 60 powershell copy powershell-2.0
$from = "\\something\1 XLS\2010_04_22\*"
$to = "c:\out\1 XLS\2010_04_22\"
copy-item $from $to -Recurse
Run Code Online (Sandbox Code Playgroud)
如果c:\ out\1 XLS\2010_04_22 \确实存在,则此方法有效.如果不存在,是否可以使用单个命令创建"c:\ out\1 XLS\2010_04_22 \".
Fri*_*ave 98
在PowerShell 2.0中,仍然无法使用Copy-Item cmdlet创建目标文件夹,您需要这样的代码:
$destinationFolder = "C:\My Stuff\Subdir"
if (!(Test-Path -path $destinationFolder)) {New-Item $destinationFolder -Type Directory}
Copy-Item "\\server1\Upgrade.exe" -Destination $destinationFolder
Run Code Online (Sandbox Code Playgroud)
如果在Copy-Item中使用-Recurse,它将在目标中创建源结构的所有子文件夹,但它不会创建实际的目标文件夹,即使使用-Force也是如此.
Sha*_*evy 74
是的,添加-Force参数.
copy-item $from $to -Recurse -Force
Run Code Online (Sandbox Code Playgroud)
mju*_*udd 12
在PowerShell 3及更高版本中,我使用带有New-Item的Copy-Item.
copy-item -Path $file -Destination (new-item -type directory -force ("C:\Folder\sub\sub\" + $newSub)) -force -ea 0
Run Code Online (Sandbox Code Playgroud)
我没有在第2版中尝试过.
| 归档时间: |
|
| 查看次数: |
111801 次 |
| 最近记录: |