Good morning, everyone.
I have a bug in my Powershell script where I am deleting the contents of a directory. The path of said directory is stored in a variable and is used in the following way:
Write-Host "* Vaciando '$RutaTempFicheros'" -ForegroundColor Yellow
Try { Remove-Item -Path $RutaTempFicheros* -Recurse -Force -ErrorAction Stop }
Catch { ManejarErrores -codigo 13 }
The problem comes when doing tests (emptying the variable, placing a new one without value, etc) and thinking that it would give an error, Powershell continues with the deletion, but in this case it empties the directory in which it is located, which in this case case is the directory where the script is stored.
Any idea why this is so or how to do it to avoid this problem?
Greetings and thanks.