1

I have a backup Folder F:\DATA\01172014 - this folder has five sub dirs \Folder1, \Folder2, Folder3, Folder4, Folder5

F:\DATA\01172014.. ..\Folder1 ..\Folder2 ..\Folder3 ..\Folder4 ..\Folder5

I want to copy the the folders 1 through 5 to the E:\Main location overwriting the existing folders

E:\Main ..\Folder1 ..\Folder2 ..\Folder3 ..\Folder4 ..\Folder5

My problem is when I run the script it finds the 01172014 folder and copy's it to the E:\Main as the same name and does not overwrite the old folders

E:\Main ..\01172014 ..\Folder1 ..\Folder2 ..\Folder3 \Folder4 ..\Folder5

My question is what am I missing

Here is my code I am using :-

Get-ChildItem -Path F:\DATA -r | 
Where-object {$_.PSIscontainer -and (($_.lastwritetime.date -eq ((get-date).adddays(-1)).date))}  |
% { Copy-Item  $_.fullName -destination E:\Main\ -force -R -whatif}

1 Answer 1

0

You're telling it to copy the date-stamped folder and contents, and it is.

Try something like this instead which will copy the contents of the date-stamped folder and its sub-folders, but not the folder itself (-Container switch retains the structure):

$BackupDir = Get-ChildItem ("F:\DATA\" + (((get-date).AddDays(-1).ToString("MMddyyyy"))))|%{$_.FullName}  

Copy-Item $BackupDir -Destination ("E:\Main\" + (Split-Path $BackupDir -leaf)) -R -Container -Force -WhatIf
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.