I'm trying to mirror a few folders for a simple backup system.
Let's assume I have the following file structure:
c:\temp\a.txt
c:\temp\b.txt
c:\temp\sub\a.txt
c:\temp\sub\112233.txt
c:\temp\sub2\pictureofaduck.jpg
My objective is to copy the whole content of c:\temp\
to a new destination (D:\mybackup\
) like this:
d:\mybackup\a.txt
d:\mybackup\b.txt
d:\mybackup\sub\a.txt
d:\mybackup\sub\112233.txt
d:\mybackup\sub2\pictureofaduck.jpg
I wrongly assumed that this should be an easy task for Copy-Item using this line:
Copy-Item 'C:\temp\' -Destination 'D:\mybackup\' -Recurse
Contrary to my expectation, Copy-Item
is really eager to keep that "temp" folder in the game. Because what whatever wildcard and -at the end combinations I try, I either get the following result or only the two files a.txt & b.txt copied.
d:\mybackup\temp\a.txt
d:\mybackup\temp\b.txt
d:\mybackup\temp\sub\123.txt
d:\mybackup\temp\sub\112233.txt
d:\mybackup\temp\sub2\pictureofaduck.jpg
Please help me, this is ridiculous.
PS: the solution to this question here doesn't work - been there. I get only the root files:
Copy entire folder structure in Powershell without re-creating root folder