function fcopy ($SourceDir,$DestinationDir)
{
Get-ChildItem $SourceDir -Recurse | Where-Object { $_.PSIsContainer -eq
$false } | ForEach-Object ($_) {
$SourceFile = $_.FullName
$DestinationFile = $DestinationDir + $_
if (Test-Path $DestinationFile) {
$i = 0
while (Test-Path $DestinationFile) {
$i += 1
Rename-Item $destinationFile ($_.BaseName + "_$i" + $_.Extension)
}
} else {
Copy-Item -Path $SourceFile -Destination $DestinationFile -Verbose
-Force
}
Copy-Item -Path $SourceFile -Destination $DestinationFile -Verbose -
Force
}
}
fcopy -SourceDir "C:\flexsource\" -DestinationDir "C:\flexreport\"
move-item "C:\flexreport\File_*.txt" "C:\flexreport\old"