BetaLeaf

Google Drive Duplicate Recycler

1 post in this topic

#1 ·  Posted (edited)

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

 

 

Edited by BetaLeaf
1 person likes this

False Positive Reporter - Mass email all anti virus vendors with an attachment of your program for fast and easy whitelisting.

PortableApps.com App Creation Wizard  - A simple GUI-based Wizard for creating PortableApps.

SoundBoard - Play any song or sound you want at the press of a hotkey.

My GitHub Page: https://github.com/BetaLeaf

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now