Hi All
Extreme novice here guys, so please excuse my simple question, however, I've been working on some code which is working when copying from one folder to another. This code first checks to make sure the source and target folders have the same name, if so, the contents (files) of source is copied to target folder. However, I'd like to take it further...
My problem is, I want to have an "Archive" Folder within the target folder and copy to this, so a 2nd level down. I can't seem to work out how to do this.
Also, please ignore the Write-Progress code, I have been trying to get this working, but can't get an accurate display (percentage complete) as there isn't an actual foreach loop doing the copying… ?
Any help is much appreciated.
Regards
Chris
# First, get a list of all target directories (i.e.: directories under $destination that have a match in $source)
$source = "c:\folder script\copy"
$destination = "c:\folder script\test"
# $countFiles = dir -Path $source -Recurse
# [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | out-null;
$targetDirs = dir -Path $source -Recurse -Force |
?{ $_.psIsContainer } |
%{ $_.FullName -replace [regex]::Escape($source), $destination } |
%{ if (Test-Path $_) { $_ }}
# $counter=1
# Then, enumerate all files from source and copy them only if the corresponding target dir exists
dir -Path $source -Recurse -Force |
?{ -not $_.psIsContainer } |
?{ Test-Path (Split-Path ($_.FullName -replace [regex]::Escape($source), $destination) -Parent)} |
copy -Force -Destination { $_.Fullname -replace [regex]::Escape($source), $destination
#$status = "Copying total of {1} Files" -f $counter,$countFiles.Count, $countFiles
#Write-Progress -Activity "Copying data to DLAB" $status -PercentComplete ($counter / $countFiles.Count*100)
}
#$counter=$CountFiles.count
#$status = "Copying total of {1} Files" -f $counter,$countFiles.Count, $countFiles
#Write-Progress -Activity "Data copy to DLAB completed" $status -PercentComplete ($counter / $countFiles.Count*100)