Repository navigation
Expand file tree
/
Copy pathUtilities.ps1
More file actions
executable file
·48 lines (39 loc) · 1.53 KB
/
Copy pathUtilities.ps1
File metadata and controls
executable file
·48 lines (39 loc) · 1.53 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
function CheckFilesAgainstCsv {
[CmdletBinding()]
Param(
[Parameter(Mandatory,HelpMessage='the path to the csv')]
[ValidateNotNullOrEmpty()]
[String]$CSVPath,
[Parameter(Mandatory,HelpMessage='The column names which contain the elements of the filename')]
[ValidateNotNullOrEmpty()]
[String[]]$ColumnsWithFileNameParts,
[Parameter(HelpMessage='The column names which contain the elements of the filename')]
[ValidateNotNullOrEmpty()]
[String]$Extension
)
if ($Extension -and $Extension.Substring(0,1) -ne ".") {$Extension = ".$Extension"}
$CSV = Import-Csv -Path $CSVPath -Encoding Unicode
$FileNames = $CSV.GetEnumerator() | ForEach-Object {
$Map = $_
($ColumnsWithFileNameParts | % {$Map."$($_)"}) -join "\"
}
[String[]]$Found = $null
[String[]]$Directories = $null
[String[]]$Failed = $null
$FileNames | % {
if (Test-Path -Path $_) {
if ($_.Substring($_.Length-1) -eq "\") {
$Directories += $_
} else {
$Found += $_
}
} elseif (Test-Path -Path "$($_)$Extension") {
$Found += "$($_)$Extension"
} else {
$Failed += "$($_)$Extension"
}
}
$Directories | % {Write-Warning "$_ is a directory"}
$Found | % {Write-Host $_ -BackgroundColor Black -ForegroundColor Cyan}
$Failed | % {Write-Host $_ -BackgroundColor Black -ForegroundColor Red}
}