Jump to content
Sign in to follow this  
GEOSoft

Cleanup duplicate links in @FavoritesDir

Recommended Posts

GEOSoft

I've gone as far as I feel like going at the present time. I will not be adding support for other browsers. Someday I may come back to this and adding a link verifier to it but for now it's just too muck code to verify tha link and if it's been redirected then update the link. Do what you want with it but please keep the source open and public domain.

Requires the Beta version to function properly.

#include<Array.au3>
$File_List = _GetFiles()
local $Url_List[1], $Gw = 500

For $I = 1 To Ubound($File_List) -1
   $disp = IniRead($File_List[$I], "InternetShortcut", "URL", "")
   If $disp = "" Then $disp = $File_List[$I], "Default", "BaseURL", "")
   _ArrayAdd($Url_List, $Disp)
Next
$Frm_Main = GUICreate("Duplicate IE Favorites Locator", $Gw, 380)
GUISetIcon(@SystemDir & "\Shell32.dll", 44)
GUICtrlCreateLabel("Select the links to be removed...", 10, 5, $Gw, 20)
$LV = GUICtrlCreateListView("Item|" & @FavoritesDir & "\", 0, 25 , $Gw, 300, 0x0008)
GUICtrlSendMsg($LV, 0x101E, 1, $Gw*.99)
GUICtrlSendMsg($LV, 0x101E, 0, 0)
$Btn_Go = GUICtrlCreateButton("Delete selected items", ($Gw/2)-140, 340, 120, 30, 1)
GUICtrlSetState($Btn_Go, 144)
$Btn_Clr = GUICtrlCreateButton("Unselect All Items", ($Gw/2) + 20, 340, 120, 30)
GUICtrlSetState($Btn_Clr, 144)
Duplicates($Url_List, $File_List)
GUISetState()
While 1
   $iCount = ControlListView ( "", "", $LV, "GetSelectedCount")
   If $iCount > 0 Then
      If GUICtrlGetState($Btn_Go) > 80 Then GUICtrlSetState($Btn_Go, 80)
      If GUICtrlGetState($Btn_Clr) > 80 Then GUICtrlSetState($Btn_Clr, 80)
   Else
      If GUICtrlGetState($Btn_Go) < 144 Then GUICtrlSetState($Btn_Go, 144)
      If GUICtrlGetState($Btn_Clr) < 144 Then GUICtrlSetState($Btn_Clr, 144)
   EndIf
   Switch GUIGetMsg()
      Case -3
         Exit
      Case $Btn_Go
         If $iCount > 0 Then
            If MsgBox ( 262180, 'Delete Files?', 'Are you sure you want to delete the ' & $iCount & ' files?', 5) = 7 Then
               ControlListView ( "", "", $LV,"SelectClear")
               ContinueLoop
            EndIf
            $sItems = StringSplit(ControlListView ( "", "", $LV, "GetSelected" , 1), "|")
            For $I = 1 To Ubound($sItems)-1
               $dItem = ControlListView ( "", "", $LV, "GetText" , $sItems[$I] , 0)
               If $dItem = "" Then ContinueLoop
               If FileExists($File_List[$dItem]) Then FileRecycle($File_List[$dItem])
            Next
            ControlListView ( "", "", $LV,"SelectClear")
         EndIf
      Case $Btn_Clr
         ControlListView ( "", "", $LV,"SelectClear")
   EndSwitch
Wend

Func _GetFiles()
   Local $bFldr = @FavoritesDir
   Local $aFiles[1], $fldrs[1] = [$bFldr]
   _FolderListToArray($fldrs[0], $fldrs)
   For $I = 0 To Ubound($Fldrs)-1
      _ArrayCreateFromFiles($Fldrs[$I], $aFiles, "*.url")
   Next
   Return $aFiles
EndFunc;<==> _GetFiles($method = 0)

Func _FolderListToArray($sSource, ByRef $vArray, $sFilter = "*", $iPath = 1, $iRecurse = 1)
   Local $tArray[1], $sPath, $nPath
   If StringRight($sSource, 1) <> "\" Then $sSource &= "\"
   $sPath = FileFindFirstFile($sSource & $sFilter)
   If $sPath <> -1 Then
      While 1
         $nPath = FileFindNextFile($sPath)
         If @Error Then ExitLoop
         If Not StringInStr(FileGetAttrib($sSource & "\" & $nPath), "D")  Then ContinueLoop
         If $iPath Then $nPath = $sSource & $nPath
         _ArrayAdd($vArray, $nPath)
         _ArrayAdd($tArray, $nPath)
      Wend
   EndIf
   If $iRecurse Then
      For $I = 1 To Ubound($tArray) -1
         _FolderListToArray($tArray[$I], $vArray)
      Next
   EndIf
EndFunc;<==> _FolderListToArray()

Func _ArrayCreateFromFiles($sSource, ByRef $vArray, $sFilter = "*", $iPath = 1)
   Local $sPath, $nPath
   If StringRight($sSource, 1) <> "\" Then $sSource &= "\"
   $sPath = FileFindFirstFile($sSource & $sFilter)
   If $sPath <> -1 Then
      While 1
         $nPath = FileFindNextFile($sPath)
         If @Error Then ExitLoop
         If StringInStr(FileGetAttrib($sSource & "\" & $nPath), "D")  Then ContinueLoop
         If $iPath Then $nPath = $sSource & $nPath
         _ArrayAdd($vArray, $nPath)
      Wend
   EndIf
EndFunc;<==> _ArrayCreateFromFiles()

Func Duplicates($aArray, $nArray)
   Local $duArray[1]
   For $I = 1 To Ubound($aArray) -1
      $Dups = _ArrayFindAll($aArray, $aArray[$I])
      If IsArray($Dups) AND (Ubound($Dups)-1) > 0 Then
         For $D = 0 To Ubound($Dups)-1
            If _ArraySearch( $duArray, $Dups[0]) <> -1 Then ContinueLoop
            For $N = 0 To UBound($dups)-1
               _ArrayAdd($duArray, $Dups[$N])
            Next
            
         Next
         $Dups = ""
      EndIf
   Next
   If Ubound($duArray)-1 > 0 Then
      For $I = 1 To Ubound($duArray)-1
         $disp = StringReplace($nArray[$duArray[$I]], ".url", "")
         $Disp = StringReplace($disp, @FavoritesDir & "\", "")
         GUICtrlCreateListViewItem($duArray[$I] & "|" & $Disp, $LV)
         If mod($I, 2) = 0 Then GUICtrlCreateListViewItem("", $LV)
      Next
   Else
      GUICtrlCreateListViewItem( "0|", $LV)
      GUICtrlCreateListViewItem( "0|There are no duplicate items to display", $LV)
      GUICtrlSetState($LV, 144)
   EndIf
EndFunc;<==> Duplicates()

Edit: Changed the Duplicates() function to allow for no duplicates found.

EDIT 2: Removed a function that was left in by error from when I was playing with using a COM object.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
Jos

Believe you need to use BETA for the missing UDF, but there are a few more errors according au3check :)

C:\path\OpenInScite51.au3(7,43) : ERROR: syntax error
    If $disp = "" Then $disp = $File_List[$I],
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\path\OpenInScite51.au3(66,61) : WARNING: $fsObj: possibly used before declaration.
        If $iRecurse Then _FoldersToArray($fsObj.getfolder($sPath),
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\path\OpenInScite51.au3(66,61) : ERROR: $fsObj: undeclared global variable.
        If $iRecurse Then _FoldersToArray($fsObj.getfolder($sPath),
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
GEOSoft

I get this error in Scite:

C:\Documents and Settings\Username\Desktop\New AutoIt v3 Script.au3 (111) : ==> Unknown function name.:

$Dups = _ArrayFindAll($aArray, $aArray[$I])

$Dups = ^ ERROR

You are probably not using the latest beta release.

EDIT: Code removed. You must use the Beta

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
GEOSoft

Believe you need to use BETA for the missing UDF, but there are a few more errors according au3check :)

C:\path\OpenInScite51.au3(7,43) : ERROR: syntax error
    If $disp = "" Then $disp = $File_List[$I],
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\path\OpenInScite51.au3(66,61) : WARNING: $fsObj: possibly used before declaration.
        If $iRecurse Then _FoldersToArray($fsObj.getfolder($sPath),
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\path\OpenInScite51.au3(66,61) : ERROR: $fsObj: undeclared global variable.
        If $iRecurse Then _FoldersToArray($fsObj.getfolder($sPath),
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
See my Edited first post for an explanation of that and the updated code. I was messing with a COM object for the folder search but it was about 50% slower than my usual code. Just forgot to remove the function.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
gseller

Awesome GeoSoft!! One suggestion would be to utilize the new listview stuff and add the checkbox in the listview for multiple or check/uncheck all for deletion.. Very Cool! Thanks

Share this post


Link to post
Share on other sites
GEOSoft

Awesome GeoSoft!! One suggestion would be to utilize the new listview stuff and add the checkbox in the listview for multiple or check/uncheck all for deletion.. Very Cool! Thanks

Thanks Gesller.

I considered that before but for now I decided not to put it in. You can stll multi-select by using the Ctrl key.Remember that select all will get rid of all those links including the ones you may have wanted to keep. Just select which ones to delete.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
ptrex

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
Sign in to follow this  

×