PoshCode Archive  Artifact [ba3ffaba59]

Artifact ba3ffaba590b3b9beca2d7e6d740d30bf4b7cda028a13c58710f9513a766fa56:

  • File Copy-FilePlus.ps1 — part of check-in [a4d2fb37ae] at 2018-06-10 14:27:08 on branch trunk — (Requires V2 CTP3) (user: halr9000 size: 1711)

# encoding: ascii
# api: powershell
# title: Copy-FilePlus
# description: (Requires V2 CTP3)
# version: 0.1
# author: halr9000
# license: CC0
# x-poshcode-id: 934
# x-archived: 2016-03-05T14:24:47
# x-published: 2010-03-11T19:48:00
#
# Use this like Copy-Item, but a GUI progress window is shown.  Original idea by Oisin Grehan <http://nivot.org>, tweaked a bit by Hal.  TODO: Needs parameter validation and handling of relative paths.  A -Force parameter would be nice.  The CopyFile static method will support overwrites.  Also needs an -AsJob parameter for non-blocking stuff.  That should be pretty trivial, just pass scriptblock to start-job.
#
<#
.SYNOPSIS
	Copies a file from one location to another while displaying a GUI progress window.
.PARAMETER Path
	Specifies the filename or FileInfo object representing file to be copied.  Right now, this must be fully-qualified, relative paths will produce an error.  Try it with Get-Item or Get-ChildItem, this works great.
.PARAMETER Destination
	Specifies the filename including path for resulting copy operation.
.EXAMPLE
	PS > Copy-FilePlus -Path c:\tmp\windows7.iso -Destination e:\tmp\windows7.iso
.EXAMPLE
	PS > Get-Item c:\tmp\windows7.iso | Copy-FilePlus -Destination e:\tmp\windows7.iso
#>
#requires -version 2
param (
	[Parameter(
		Mandatory = $true, 
		ValueFromPipeline = $true
	)]$Path,
	[Parameter(Mandatory=$true)]
	[string]
	$Destination
)
try {
	add-type -a microsoft.visualbasic
	[Microsoft.VisualBasic.FileIO.FileSystem]::CopyFile(
		$Path,
		$Destination,
		[Microsoft.VisualBasic.FileIO.UIOption]::AllDialogs,
		[Microsoft.VisualBasic.FileIO.UICancelOption]::ThrowException
	)
} catch { $_ }