Advertisement
Wasif_Hasan_

DuplicateImageScanner.ps1

Sep 18th, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $sig=@'
  2. public static void ShowConsoleWindow(int state)
  3. {
  4.  var handle = GetConsoleWindow();
  5.  ShowWindow(handle,state);
  6. }
  7. [System.Runtime.InteropServices.DllImport("kernel32.dll")]
  8. static extern IntPtr GetConsoleWindow();
  9. [System.Runtime.InteropServices.DllImport("user32.dll")]
  10. static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
  11. '@
  12. $hc=Add-Type -mem $sig -name Hide -Names HideConsole -Ref System.Runtime.InteropServices -Pas
  13. $hc::ShowConsoleWindow(0)
  14. [console]::title="Duplicate Image Scanner (c) Wasif Hasan | Sep 2020"
  15. $eXt=@('.jpg','.png','.gif','.jpeg','.webp','.tiff','.psd','.raw','.bmp','.heif','indd','.svg')
  16. @('system.windows.forms','system.drawing')|%{add-type -as $_}
  17. $s=[windows.forms.form]::new();$s.size=[drawing.size]::new(400,850);$s.StartPosition="CenterScreen";$s.Text="Select drives to scan"
  18. $drives=gdr -p "FileSystem"|select -eXp name
  19. $top=20;$left=50;$drives|%{
  20. $c=$_.split(" ")-join"_";$top += 20
  21. iex "`$$($c) = New-Object System.Windows.Forms.CheckBox;`$$($c).Top = $($top);`$$($c).Left = $($left);`$$($c).Anchor='Left,Top';`$$($c).Parent='';`$$($c).Text='$($_)';`$$($c).Autosize=`$true;if('$_' -in `$drives){`$$c.Checked=`$true};`$s.Controls.Add(`$$c)"
  22. }
  23. $ok=New-Object System.Windows.Forms.Button;$ok.Text='OK';$ok.Top=770;$ok.Left=290
  24. $ok.add_click({$s.Close()});$s.Controls.AddRange($ok)
  25. $sa=New-Object System.Windows.Forms.Button;$sa.Text='Select All';$sa.Top=770;$sa.Left=200
  26. $sa.add_click({$s.Controls|?{($_.Checked) -or !($_.Checked)}|%{try{$_.Checked=$True}catch{}}});$s.Controls.AddRange($sa)
  27. $null=$s.ShowDialog()
  28. $choices=$s.Controls|?{$_.Checked}|select -eXp Text
  29. $i=0;$choices|%{$choices[$i]=$_+':\';$i++}
  30. $f=[windows.forms.form]::new();$f.Size=[drawing.size]::new(600,100);$f.StartPosition="CenterScreen";$f.Text="Please wait"
  31. $l=[windows.forms.label]::new();$l.Text="Please wait until the scan is complete........";$l.Font="Segoe UI,16";$l.AutoSize=$true;$f.Controls.AddRange($l)
  32. $null=$f.ShowDialog()
  33. $files=@();$hCols=@();$choices|%{
  34.  dir $_ -r|?{$_.eXtension-in$eXt}|%{
  35.    $h=get-filehash $_.fullname -a 'SHA256'|select -eXp hash
  36.    if($h-in$hCols){$files+=$_.fullName}else{$hCols+=$h}
  37. }};$f.Close()
  38. $del=$files|ogv -t "Duplicate images (Hold CTRL and select the ones to delete)" -p
  39. $del|%{rm "$_" -fo}
  40. [windows.forms.messagebox]::Show("Thanks for using!","Duplicate image scanner","OK","Information")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement