0% found this document useful (0 votes)
8 views1 page

Compare File Version

This function copies files from a source directory to a destination directory recursively while handling any file name conflicts. It gets all non-folder files from the source, copies each to the destination, and renames any duplicates by appending a number.

Uploaded by

Michael
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Compare File Version

This function copies files from a source directory to a destination directory recursively while handling any file name conflicts. It gets all non-folder files from the source, copies each to the destination, and renames any duplicates by appending a number.

Uploaded by

Michael
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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"

You might also like