Last active
February 23, 2017 02:36
-
-
Save douglascodes/40c6203ff47ddd67ca24f9403560b93a to your computer and use it in GitHub Desktop.
Function for testing files in similar paths but different roots exist in both places
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Script for testing file existence in two places | |
# PS C:\> . .\removeOldBackups.ps1 | |
# PS C:\> existsInBoth -DestRoot 'C:\Program Files\' -SourceRoot 'C:\Program Files (x86)\' -CommonPath "Common Files" | |
# True | |
# PS C:\> existsInBoth -DestRoot 'C:\Program Files\' -SourceRoot 'C:\Program Files (x86)\' -CommonPath "UnmatchedFile" | |
# False | |
function existsInBoth{ | |
param ( [string] $SourceRoot, | |
[string] $DestRoot, | |
[string] $CommonPath) | |
$result = $false | |
$sourceTarget = [System.IO.Path]::Combine($SourceRoot, $CommonPath) | |
$destTarget = [System.IO.Path]::Combine($DestRoot, $CommonPath) | |
if ((Test-Path -ErrorAction Ignore ($sourceTarget)) -and (Test-Path -ErrorAction Ignore ($destTarget) )) { | |
$result = $true | |
} | |
return $result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment