How to copy certain files (w/o folder hierarchy), but do not overwrite existing files?

后端 未结 5 2048
孤街浪徒
孤街浪徒 2020-12-08 09:03

I need to copy all *.doc files (but not folders whose names match *.doc) from a network folder \\\\server\\source (including files in

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-08 09:13

    # Get all *.doc files under \\server\source
    Get-ChildItem -Path \\server\source *.doc -Recurse |
        # Filter out directores
        Where-Object { -not $_.PsIsContainer } | 
        # Add property for destination
        Add-Member ScriptProperty -Name Destination -Value { Join-Path 'C:\destination' $this.Name } -PassThru |
        # Filter out files that exist on the destination
        Where-Object { -not (Test-Path -Path $_.Destination -PathType Leaf } | 
        # Copy. 
        Copy-Item
    

提交回复
热议问题