Reputation: 2311
This script will only delete files if all exists. How to rewrite the script, so it will delete files even one of the file is missing.
$paths = $outpath, $outPath2, $outPath3
if ((test-path $paths) -notcontains $false){
Remove-Item -Path $paths
}
Upvotes: 0
Views: 310
Reputation: 408
If the problem is the error exception when it doesn't find a file , you can use the remove-item parameter -erroraction silentlycontinue :
$paths| % { Remove-Item "$_" -ErrorAction SilentlyContinue }
Upvotes: 2