I want to change the extension of a few files from .cap to .zip. I wrote following code in powershell:
Copy-Item $sourceFileLocation\*.cap $Temp -Force
But what if the same files with .zip extension already exist? It gives the following error on the console:
Rename-Item : Cannot create a file when that file already exists.
At E:\ExtractHashId.ps1:32 char:23
+ dir $Temp\*.cap | Rename-Item -NewName{$_.Name -replace ".cap", ".zip"}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (C:\Users\v-kamo...News_Locals.cap:String) [Rename-Item], IOException
+ FullyQualifiedErrorId : RenameItemIOError,Microsoft.PowerShell.Commands.RenameItemCommand
So What I need to do to overwrite these files?