param(
$DriverFolder=$(throw "DriverFolder is null"),
$CatFolder=$(throw "CatFolder is null")
)
$Script:DriverCats = New-Object -TypeName System.Collections.ArrayList
$Script:Cats=$ar = New-Object -TypeName System.Collections.ArrayList
function FindCatPath($DriverFolder)
{
$CatArray = New-Object -TypeName System.Collections.ArrayList
Get-ChildItem $DriverFolder -Recurse | ForEach-Object{
if($_.Extension -eq '.txt')
{
$CatArray.Add($_)
}
}
return $CatArray
}
function ReplaceFile($SourceFile,$TagretFile)
{
Copy-Item -Path $SourceFile -Destination $TagretFile -Force -Recurse
}
#main
$DriverCats=FindCatPath $DriverFolder
$Cats=FindCatPath $CatFolder
for($i=1;$i -lt $DriverCats.Count;$i++)
{
for($j=1;$j -lt $Cats.Count;$j++)
{
if($DriverCats[$i].Name -eq $Cats[$j].Name)
{
ReplaceFile $Cats[$j].FullName $DriverCats[$i].FullName
}
}
}