basketcase

Search for File - If Exists - Menu to Delete

Sep 19th, 2010
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $a = ('*.bat','*.txt')
  2. $b = Get-ChildItem $a
  3.  
  4. Function deleteFiles {
  5. $title = "Delete Files"
  6. $message = "Do you want to delete the files in the folder?"
  7.  
  8. $yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", `
  9.     "Deletes all files in the folder."
  10.    
  11. $no = New-Object system.Management.Automation.Host.ChoiceDescription "&No", `
  12.     "Don't delete the files in the folder."
  13.    
  14. $options = [System.Management.Automation.Host.ChoiceDescription[]] ($yes,$no)
  15.  
  16. $result = $Host.UI.PromptForChoice($title, $message, $options, 0)
  17.  
  18.     switch ($result) {
  19.         0 {Write-Host "Hot Damn!"}
  20.         1 {Write-Host "Darn!"}
  21.         }
  22. }
  23.  
  24.  
  25. if($b){deleteFiles}
  26.  
  27.  
  28. else {Write-Host "Nope...Nothing there"}
Add Comment
Please, Sign In to add comment