-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileCopyDotNet.ps1
More file actions
50 lines (40 loc) · 1.67 KB
/
Copy pathFileCopyDotNet.ps1
File metadata and controls
50 lines (40 loc) · 1.67 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
function ExitWithError {
param ($ErrorMessage)
$Host.UI.WriteErrorLine($ErrorMessage)
$Host.UI.Write("`n`tUsage:`n`n`t.\FileCopyCmdlet.ps1 Source Target`n")
Exit
}
function Validate {
param ($InputValues)
[string]$errorMessage = ""
if ($InputValues[0] -eq $null -or -not ([System.IO.File]::Exists($InputValues[0])))
{
[string]$directoryName = [System.IO.Path]::GetDirectoryName($InputValues[0])
[string]$fileName = [System.IO.Path]::GetFileName($InputValues[0])
if (-not [System.IO.Directory]::Exists($directoryName) -or -not [System.IO.Directory]::EnumerateFiles($directoryName, $fileName))
{
$errorMessage = "Sorry, `"" + $InputValues[0] + "`" doesn't seem to exist."
ExitWithError $errorMessage
}
}
if ($InputValues[1] -eq $null -or -not ([System.IO.Directory]::Exists($InputValues[1])))
{
$errorMessage = "Please specify a valid directory as the second argument."
ExitWithError $errorMessage
}
[string]$predictedResult = $InputValues[1] + ([System.IO.Path]::GetFileName($InputValues[0]))
if ([System.IO.File]::Exists($predictedResult))
{
$errorMessage = "The file or files " + $predictedResult + " already exist!"
ExitWithError $errorMessage
}
if ($InputValues[2] -ne $null)
{
[string]$errorMessage = "Sorry, `"" + $InputValues[2] + "`" is not a valid argument."
ExitWithError $errorMessage
}
}
$Host.UI.Write("`nFileCopyCmdlet created September 18, 2015 by Chaim Eliyah for ShiftWise`n")
Validate $args
#[System.IO.File]::Copy($args[0], $args[1], $false)
$Host.UI.Write("`nExiting without errors.")