Skip to content

Instantly share code, notes, and snippets.

@douglascodes
Last active February 23, 2017 02:36
Show Gist options
  • Save douglascodes/40c6203ff47ddd67ca24f9403560b93a to your computer and use it in GitHub Desktop.
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
# 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