0

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 
}

1 Answer 1

2

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  }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.