;#RequireAdmin #include #include #include #include ;Change to script directory. This fixes searching in the wrong folder when used from a shortcut with an improperly set Working Directory. FileChangeDir(@ScriptDir) ;Enables a Progress Bar ProgressOn("Recycling Duplicates", "Getting list of files") ;Get a list of files to search Global $aFiles = _FileListToArrayRec(@WorkingDir, "*", $FLTA_FILES, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH) ;Create an array for the list of duplicate files. Global $aDuplicateList[0] ;Start a timer to update the Progress Bar. Global $timer = TimerInit() ;Assign a variable to track the number of found duplicates. Global $vProgressCounter = 0 ;Searches every file recursively in the @ScriptDir folder for duplicates to recycle. For $i = 1 To $aFiles[0] ;If timer is greater than specified value on the right, update the Progress Bar with the current information. If TimerDiff($timer) > (1000 / 29) Then ;Update the Progress Bar ProgressSet(($i * 100) / ($aFiles[0]), "Searching " & $i & " of " & $aFiles[0] & " files for duplicates." & @CRLF & "Found " & $vProgressCounter & " duplicates.", "Searching for Duplicates...") ;Start a new timer to update the Progress Bar. $timer = TimerInit() EndIf ;Search folder for duplicates to recycle. _Search($aFiles[$i]) Next ;This allows the progress bar to fully complete itself graphically. ProgressSet(100, "Searching " & $i & " of " & $aFiles[0] & " for duplicates." & @CRLF & "Found " & $vProgressCounter & " duplicates.", "Searching for Duplicates...") Sleep(500) If $vProgressCounter = 0 Then ;Disables Progress Bar ProgressOff() ;Inform user that no duplicates were detected. MsgBox($MB_APPLMODAL, "Recycling Duplicates", "No duplicates were found. The program will now exit.") Exit EndIf ;Get the number of duplicates so we can properly update the progress bar. _ArrayInsert($aDuplicateList, 0, UBound($aDuplicateList), 0) ;Restart the timer $timer = TimerInit() ;For each duplicate, recycle the file. For $j = 1 To $aDuplicateList[0] ;If timer is greater than specified value on the right, update the Progress Bar with the current information. If TimerDiff($timer) > (1000 / 29) Then ;Update the Progress Bar ProgressSet(($j * 100) / ($aDuplicateList[0]), "Recycling duplicate " & $j & " of " & $aDuplicateList[0] & ".", "Recycling Duplicates...") ;Start a new timer to update the Progress Bar. $timer = TimerInit() EndIf ;Recycle the file $iRecycle = FileRecycle($aDuplicateList[$j]) If $iRecycle = False Then MsgBox($MB_SYSTEMMODAL, "Recycling Duplicates", "An error occurred whilst recycling the file.") Next ;This allows the progress bar to fully complete itself graphically. ProgressSet(100, "Recycling duplicate " & $j & " of " & $aDuplicateList[0] & ".", "Recycling Duplicates...") Sleep(500) ;Disables Progress Bar ProgressOff() ;Inform user that all detected duplicates have been moved to the Recycling Bin. This implies that duplicates can be restored from the recycling bin or permanently deleted. MsgBox($MB_APPLMODAL, "Recycling Duplicates", "All found duplicates have been moved to the Recycling Bin.") ; Open the recycle bin by using the following CLSID. ShellExecute("::{645FF040-5081-101B-9F08-00AA002F954E}") Func _Search($sPath) Select ;Mark the following sub-strings as duplicates. Case StringInStr($sPath, "(1)") Case StringInStr($sPath, "(2)") Case StringInStr($sPath, "(3)") Case StringInStr($sPath, "(4)") Case StringInStr($sPath, "(5)") Case StringInStr($sPath, "(6)") Case StringInStr($sPath, "(7)") Case StringInStr($sPath, "(8)") Case StringInStr($sPath, "(9)") Case StringInStr($sPath, "(conflicted)") Case StringInStr($sPath, "(conflicted 1)") Case StringInStr($sPath, "(conflicted 2)") Case StringInStr($sPath, "(conflicted 3)") Case StringInStr($sPath, "(conflicted 4)") Case StringInStr($sPath, "(conflicted 5)") Case StringInStr($sPath, "(conflicted 6)") Case StringInStr($sPath, "(conflicted 7)") Case StringInStr($sPath, "(conflicted 8)") Case StringInStr($sPath, "(conflicted 9)") Case StringInStr($sPath, "-BetaLaptop") Case Else ;Everything else is ignored. Return EndSelect ;Add to recycle list. $iret = _ArrayAdd($aDuplicateList,$sPath) If $iret = -1 Then MsgBox($MB_SYSTEMMODAL, "Recycling Duplicates", "An error occurred when adding the file to the list of duplicates." & @CRLF & "Error: " & @error) ;Increment counter for found duplicate items $vProgressCounter += 1 EndFunc ;==>_Search