forked from stcu/SharedScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdate-Files.ps1
More file actions
34 lines (29 loc) · 1.17 KB
/
Copy pathUpdate-Files.ps1
File metadata and controls
34 lines (29 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<#
.SYNOPSIS
Copies specified source files that exist in the destination directory.
.INPUTS
System.String of paths to copy from, if matches exist in the destination.
.EXAMPLE
Update-Files.ps1 C:\Source\*.txt D:\Dest
Copies *.txt files from C:\Source to D:\Dest that exist in both.
#>
#Requires -Version 3
[CmdletBinding(SupportsShouldProcess=$true)][OutputType([void])] Param(
# Path(s) to copy files from, wildcards allowed.
[Parameter(Position=0,ValueFromPipelineByPropertyName=$true,ValueFromPipeline=$true,Mandatory=$true)][string[]] $Path,
# Folder to copy files to, if they already exist there.
[ValidateScript({Test-Path $_ -PathType Container})][Parameter(Position=1)][string] $Destination,
# Indicates files should only be copied if they are newer.
[switch] $NewerOnly
)
Process
{
foreach($file in Resolve-Path $Path)
{
$destfile = Join-Path $Destination ([IO.Path]::GetFileName($file))
if(!(Test-Path $destfile -PathType Leaf)) {continue}
if((!$NewerOnly -or (Test-NewerFile.ps1 "$destfile" "$file")) -and
$PSCmdlet.ShouldProcess("'$file' over '$destfile'",'copy'))
{cp $file $destfile}
}
}