C:.
| checkMotherscript_v3.ps1
|
+---aa
| test.sql
|
+---aaa
| | mother-a.sql (promt toto.sql
@@aa\f1aa.sql
test.sql)
| |
| +---aa
| | f1aa.sql
| | f2aa.sql
| | f3aa.sql
| |
| +---ab
| | f1ab.sql
| | f2ab.sql
| | f3ab.sql
| |
| +---ac
| | f1a.sql
| | f2a.sql
| | f3a.sql
| | |
| |
| +---ca
| | f1ca.sql
| | f2ca.sql
| | f3ca.sql
| |
| +---cb
| | f1cb.sql
| | f2cb.sql
| | f3cb.sql
| |
| \---cc
| f1cc.sql
| f2cc.sql
| f3cc.sql
|
+---bbb
| | moeder-b.sql (@@ba\f1ba.sql
@@bb\f1bb.sql
test.sql)| |
| +---ba
| | f1ba.sql
| | f2ba.sql
| | f3ba.sql
| |
| +---bb
| | f1bb.sql
| | f2bb.sql
| | f3bb.sql
| |
| \---bc
| f1bc.sql
| f2bc.sql
| f3bc.sql
|
\---ccc
| moeder-c.sql (@@ca\f1ca.sql
@@cb\f1cb.sql
@@cc\f1cc.sql
@@cc\f2cc.sql
@cc\f3cc.sql
test-c.sql)
|
+---ca
| f1ca.sql
| f2ca.sql
| f3ca.sql
|
+---cb
| f1cb.sql
| f2cb.sql
| f3cb.sql
|
\---cc
f1cc.sql
f2cc.sql
f3cc.sql
C:\tmp\testsql\04003401\checkMotherscript_v3.ps1
param([string]$Path=".\",
[string]$Target=($Path + "result.txt"),
[switch]$Help,
[switch]$Verbose )
Function help()
{
Write-Host "NAME"
Write-Host " checkMotherscript -root <root> "
Write-Host
Write-Host "SYNTAX"
Write-Host " checkMotherscript [-?]"
Write-Host " checkMotherscript [-Verbose] [[-Path] <string>]"
Write-Host " checkMotherscript [-Verbose] [[-Target] <file-name>] [[-Path] <string>]"
Write-Host
Write-Host "PARAMETER"
Write-Host " -Help = help"
Write-Host " -Path = start path"
Write-Host " -Verbose = Verbose run"
Write-Host (" -Target = file-name for output, default is " + $Target)
Write-Host
Write-Host "VERSION"
Write-Host " 3"
Write-Host
Write-Host "DATE"
Write-Host " 26-5-2014"
Write-Host
Write-Host "AUTHEUR"
Write-Host " Pascal"
Write-Host
Write-Host "REMARKS"
Write-Host " Search mother-scripts en sql files and compare them two way."
Write-Host " All sql-files must be found in the mother-scrips"
Write-Host " and all sql-files must be in the mother-files."
}
Function go()
{
param(
[Parameter(Mandatory=$true)][string]$iBasePath,
[Parameter(Mandatory=$false)][int]$iDeep,
[Parameter(Mandatory=$false)][string]$iPathMother
)
if($Verbose.IsPresent)
{
Write-Host $iBasePath
}
if( $iDeep -eq $null -or $iDeep -eq 0 ){
$iDeep = 0
# delete Target-file
if (Test-Path $Target )
{
Remove-Item $Target
}
Get-Date > ($Target)
}
$iDeep = $iDeep + 1
#Write-Host ("Begin" + $iDeep)
$files = Get-ChildItem $iBasePath -ErrorAction silentlycontinue
$mother = Get-ChildItem $iBasePath -Name -Include *moeder*.sql -ErrorAction silentlycontinue
if( $mother -ne $null )
{
$motherContent = Get-Content $($iBasePath + $mother)
$motherSqlContent = @()
for ($i=0; $i -lt $motherContent.Count; $i++) {
if($motherContent[$i].ToLower().Contains(".sql") -and -not $motherContent[$i].ToLower().Contains("prompt"))
{
$motherSqlContent += @($motherContent[$i].Replace( "@","") )
}
}
$pathMotherList = $iBasePath.split("\")
$motherDeep = $iDeep
$pathMother = ""
for ($i=0; $i -lt $pathMotherList.Count; $i++) {
if ($i -gt $iDeep )
{
if ($pathMother.Length -eq 0)
{
$pathMother = $pathMotherList[$i]
} else
{
$pathMother = $pathMother + $pathMotherList[$i]
}
}
}
}
[string[]]$children = Get-ChildItem $iBasePath -Name -Include *.sql -Exclude *moeder*.sql -ErrorAction silentlycontinue
if( $children -ne $null)
{
if($iPathMother -eq $null -or $iPathMother -eq "")
{
"No Mother-file found for:" >> ($Target)
$children >> ($Target)
"" >> ($Target)
$children = $null
}
else
{
for ($i=0; $i -lt $children.Count; $i++)
{
$children[$i] = $iPathMother + $children[$i]
}
}
}
for ($i=0; $i -lt $files.Count; $i++) {
if ($files[$i].Attributes -eq "Directory")
{
$paramBasePath = $iBasePath + $files[$i].BaseName + "\"
$paramPathMother = $null
if($pathMother -ne $null)
{
if($pathMother.Length -eq 0)
{
$paramPathMother = $files[$i].BaseName + "\"
}
else
{
$paramPathMother = $pathMother + $files[$i].BaseName + "\"
}
}
$children2 = go ($paramBasePath) ($iDeep) ($paramPathMother)
if($children2 -ne $null)
{
$children = $children + $children2
}
}
}
if( $motherDeep -ne $null -and $motherDeep -eq $iDeep)
{
if($children -eq $null )
{
$children = ""
}
$mother >> ($Target)
Compare-Object $children $motherSqlContent -IncludeEqual >> ($Target)
return $null
}
return $children
}
if($Help.IsPresent)
{
help
return $null
} else
{
$StartPath = $Path
if($Path -eq "\"){
$StartPath = (get-location).Drive.Root
}
if($Path -eq ".."){
$StartPath = ($Path + "\")
}
go $StartPath
Get-Content ($Target)
return $null
}