Guest User

Untitled

a guest
Nov 23rd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. [CmdLetBinding()]
  2. Param(
  3. )
  4. Add-Type -AssemblyName Microsoft.VisualBasic
  5.  
  6. function Remove-Item-ToRecycleBin($Path) {
  7. $item = Get-Item -Path $Path -ErrorAction SilentlyContinue
  8. if ($item -eq $null)
  9. {
  10. Write-Error("'{0}' not found" -f $Path)
  11. }
  12. else
  13. {
  14. $fullpath=$item.FullName
  15. Write-Verbose ("Moving '{0}' to the Recycle Bin" -f $fullpath)
  16. if (Test-Path -Path $fullpath -PathType Container)
  17. {
  18. [Microsoft.VisualBasic.FileIO.FileSystem]::DeleteDirectory($fullpath,'OnlyErrorDialogs','SendToRecycleBin')
  19. }
  20. else
  21. {
  22. [Microsoft.VisualBasic.FileIO.FileSystem]::DeleteFile($fullpath,'OnlyErrorDialogs','SendToRecycleBin')
  23. }
  24. }
  25. }
  26.  
  27.  
  28. $status = git status -s | ? { $_.StartsWith("??")}
  29.  
  30.  
  31. $status | % {
  32. $file = $_.Replace("?? ", ".\").Replace("/","\")
  33. if(Test-Path($file)){
  34. Write-Warning "$file"
  35. }
  36. }
  37.  
  38.  
  39. $confirm = Read-Host -Prompt "Are you sure you want to remove all the untracked files and folders?? [Yes] to confirm"
  40. if($confirm -ne "Yes"){
  41. Write-Host "No files is deleted"
  42. return;
  43. exit;
  44. }
  45.  
  46. $status | % {
  47.  
  48. $file = $_.Replace("?? ", ".\").Replace("/","\")
  49. if(Test-Path($file)){
  50. Remove-Item-ToRecycleBin((ls $file).FullName)
  51. }
  52. }
Add Comment
Please, Sign In to add comment