bdukes / PowerShellModules

A collection of PowerShell modules
Apache License 2.0
44 stars 9 forks source link

does not remove dir/files if name has [] or () #9

Closed Mortyfar closed 2 years ago

Mortyfar commented 2 years ago

Hello @bdukes I encountered a problem, where the directory containing [ ] did not get removed, also it gave no error message. (i.e. D:\test[1]) When trying to remove files in the given folder, also nothing happens, and no errors.

However, if the name contains ( ) that gives out an error: ;D:>powershell "Remove-ItemSafely D:\test(1)" ;Remove-ItemSafely` : A positional parameter cannot be found that accepts argument '1'. ;At line:1 char:1 ;+ Remove-ItemSafely D:\test(1) ;+ ~~~~~~~~~~~~ ; + CategoryInfo : InvalidArgument: (:) [Remove-ItemSafely], ParameterBindingException ; + FullyQualifiedErrorId : PositionalParameterNotFound,Remove-ItemSafely

I have tried containing the argument in different ways with either ' or " but nothing seems to work...

Hope there is a workaround for this issue :)

bdukes commented 2 years ago

I believe you need to pass that path using the -LiteralPath parameter, e.g. Remove-ItemSafely -LiteralPath 'D:\test(1)'. Hope it helps!

Mortyfar commented 2 years ago

Oh my, I can not believe I did not try that :) Thank you, that works.