user664481
user664481

Reputation: 2311

Powershell - remove files

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

Answers (1)

dvjz
dvjz

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

Related Questions