I'm trying to delete a folder in an install script using PowerShell. The script copies a bunch of files to a distribution folder (using RoboCopy) and then cleans up superfluous files and folders.
I seem to be unable to use PowerShell to delete a folder name c:\installs\wwhelp\Editors\.vs
even after having set permissions in the Powershell Console running as admin.
I essentially do this after copying and cleaning out the .vs folder:
set source=\wwapps\wwhelp
set target=\installs\wwhelp
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy UnRestricted
robocopy $source\Editors $target\Editors /MIR
deletefiles $target\Editors\.vs\*.* -r -f <-- deletes files & folder recursively
rd $target\Editors\.vs
This fails with:
rd : Cannot remove item
C:\installs\wwhelp\editors\.vs
: You do not have sufficient access rights to perform this operation.
The folder is empty and I'm running as admin and I've set the execution policy. If I create a folder called vs
in the same folder structure the remove works.
Likewise running the rd
command in the command window with Admin works.
Any ideas why I get a security exception on a folder that starts with a .
in Powershell?
.vs
is a folder? Somewhere the \ seems to have gone missing. Can you tryrd c:\\installs\\wwhelp\\editors\\.vs
\
when usingrd
md f:\test\.vs
followed byrd f:\test\.vs
works as expected with no error messages - in both cmd and powershell. The OP has a different problem than escaping anything.