Take the 2-minute tour ×

When I run a recursive Copy-Item from a folder that has sub folders to a new folder that contains the same sub folders as the original, it throws an error when the subfolders already exist. How can I suppress this because it is a false negative and can make true failures harder to see.


Copy-Item "C:\realFolder\*" "C:\realFolder_new" -recurse

Copy-Item : Item with specified name C:\realFolder_new\subFolder already exists.

Thank you.


share|improve this question
Does adding -Force solve the problem? –  Lee Grissom Apr 5 '13 at 20:49
add comment

2 Answers

up vote 9 down vote accepted

You could try capturing any errors that happen, and then decide whether you care about it or not:

copy-item "C:\realFolder\*" "C:\realFolder_new" -recurse -ErrorVariable capturedErrors -ErrorAction SilentlyContinue
$capturedErrors | foreach-object { if ($_ -notmatch "already exists") { write-error $_ } }
share|improve this answer
Thank you, this works. Finally getting a chance to implement it and test today :) –  user1161625 Mar 9 '12 at 18:20
add comment

You can set the error handling behavior to ignore using:

Copy-Item "C:\realFolder\*" "C:\realFolder_new" -recurse -ErrorAction SilentlyContinue

However this will also suppress errors you did want to know about!

share|improve this answer
Yeah... that only sorta helps :) Is the already exists thing a bug in the Copy-Item cmdlet? Seems like a waste of output- if it's already there and I was about to create it then who cares.. at least give me a -slientOnExistingDirs or -verbose switch, right? Thanks for your help though.. I'll think about that option. –  user1161625 Feb 24 '12 at 22:21
add comment

Your Answer


