Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Help copy and remove item

$
0
0

Hello,
Iall the filesin the source directoryand sub-directoriesdizinlerdrefiles fromtarget1andtarget2preservingthe directory structureyou wantto copyanddeletefiles that are copied.(Duringthe deletionjustwant todeletion of files,I wantthe protectionin the source directorystructure.)
Thank you very muchfor your help.

$source = "D:\\Source\"
$Target1="D:\\Target1\"
$Target2="D:\\Target2\"
$Files = get-childitem   $source  -Recurse
foreach ($file in $Files|  Where-Object { -not $_.psIsContainer }  ){
        write-host $file.fullname
        Copy-Item $file.FullName  $Target1 -Recurse -force
        Copy-Item $file.FullName  $Target2 -Recurse -force
        Remove-Item $file.fullname -force
}


Viewing all articles
Browse latest Browse all 6937

Trending Articles