如何使用cmd或PowerShell进行版本控制的副本文件?

时间:2017-08-28 15:31:05

标签: windows powershell cmd

在Windows上手动复制文件时,它会检测是否存在同名文件,然后建议对其进行版本控制。如何使用Windows命令提示符和PowerShell执行此操作?

我想知道是否有一些我可以从PowerShell调用的Windows API,而不是从头开始做事。

see image

1 个答案:

答案 0 :(得分:0)

简单的谷歌搜索"复制替换gui powershell"将此作为第二个选项

找到http://blog.backslasher.net/copying-files-in-powershell-using-windows-explorer-ui.html

function Copy-ItemUsingExplorer{
    param(
        [string]$source,
        [string]$destination,
        [int]$CopyFlags
    )

    $objShell = New-Object -ComObject 'Shell.Application'    
    $objFolder = $objShell.NameSpace((gi $destination).FullName)
    $objFolder.CopyHere((gi $source).FullName,$CopyFlags.ToString('{0:x}'))
}


Copy-ItemUsingExplorer -source C:\Users\Default\Desktop\End -destination C:\Users\Default\Desktop\Start