Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 07/15/2017 in all areas

  1. Occasionally, Google Drive freaks out and creates a duplicate when it finds a conflict. This program will find these conflicts and move them to the recycling bin so the user can either permanently delete it or restore it and delete the other version of the conflict. This can easily be expanded to include other cloud services by adding/modifying the search string to/in the blacklist at _Search(). There is a batch version out there on the web that I took inspiration from. It was slow and only checked for one specific kind of string. Each one you added increased the time multiplicatively. This version is much faster and efficient. It can search about 21,000 folders with 200,000 files total in about 9 seconds. #include <File.au3> #include <FileConstants.au3> #include <MsgBoxConstants.au3> ;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 folders") ;Get a list of folders to search $aFolders = _FileListToArrayRec(@ScriptDir, "*", $FLTA_FOLDERS, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH) ;Start a timer to update the Progress Bar. Global $timer = TimerInit() ;Searches the @ScriptDir ROOT folder for duplicates to recycle. _Search(@ScriptDir) ;Searches every folder recursively in the @ScriptDir ROOT folder for duplicates to recycle. For $i = 1 To $aFolders[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) / ($aFolders[0]), "Searching " & $i & " of " & $aFolders[0] & " for copies.", "Recycling Duplicates...") ;Start a new timer to update the Progress Bar. $timer = TimerInit() EndIf ;Change Working Directory to the folder being searched. FileChangeDir($aFolders[$i]) ;Search folder for duplicates to recycle. _Search($aFolders[$i]) Next ;This allows the progress bar to fully complete itself graphically. ProgressSet(100, "Searching " & $aFolders[0] & " of " & $aFolders[0] & " for copies.", "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($Dir) ; Assign a Local variable the search handle of all files in the current directory. Local $hSearch = FileFindFirstFile("* (?)*") ; Check if the search was successful. If not, returns False and search the next folder. If $hSearch = -1 Then Return False ; Assign a Local variable the empty string which will contain the files names found. Local $sFileName = "", $iResult = 0 While 1 $sFileName = FileFindNextFile($hSearch) ; If there is no more file matching the search, exit the loop and search the next folder. If @error Then ExitLoop Select ;The Blacklist Case StringInStr($sFileName, "(1)") Case StringInStr($sFileName, "(2)") Case StringInStr($sFileName, "(3)") Case StringInStr($sFileName, "(4)") Case StringInStr($sFileName, "(5)") Case StringInStr($sFileName, "(6)") Case StringInStr($sFileName, "(7)") Case StringInStr($sFileName, "(8)") Case StringInStr($sFileName, "(9)") Case Else ;Everything else is NOT considered a duplicate and won't be recycled. ExitLoop EndSelect ; Recycle the file. $iRecycle = FileRecycle(@WorkingDir & "\" & $sFileName) If $iRecycle = False Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst deleting the file.") WEnd ; Close the search handle. FileClose($hSearch) EndFunc ;==>_Search
    1 point
×
×
  • Create New...