Sign in to follow this  
Followers 0
gear

Quickly open any folder in disks

2 posts in this topic

A program can find and folder in your disks, it can work because the program will search the disks and build the folder name index files and save them in a specified folder. later this program read these indexfiles and then can find any folder included in these files.

normally the time to build index files is about 10 minutes, later the search time is as quickly as 1-2 seconds.

;; This program can find the folder quickly. You just need to enter the full or partial name of the folder you want to find
; then it can find it and list the matched folder in the list box, you
;click on the one you want to open, it will open the explorer.
;Pause key can hide or show the GUI window.
; This program is also a example to learn how to manipulate 1-dimension and 2-dimension Array
#include <Array.au3>
#include <File.au3>
#include <GuiList.au3>
$IdleTimeToHide = 10000;the time the window will hide after use
$MaxFolderDepth = 8;how deep the folder within the disk.
$Paused = 0;control toggle the window hide or show
$TheFolderToSaveIndexFiles = "E:\FolderIndex\";this is the folder to save all the index files
$MaxFolderInOneDisk = 10000;here only can save $MaxFolderInOneDisk folders in one disk, but it is enough normally
HotKeySet("{PAUSE}", "TogglePause")
#region --- GuiBuilder code Start ---
; Script generated by AutoBuilder 0.6 Prototype

#include <GuiConstants.au3>
GUICreate("Quickly Open Folder", 848, 319, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
$OpenFolderTitle = WinGetTitle("");get the GUI window title
;;$OpenFolderTitle=WinGetHandle($OpenFolderTitle); it can not work with the use of winhandle!
$FolderNameInput = GUICtrlCreateLabel("The folder you want to find:", 560, 10, 350, 30)
$FolderNameToSearch = GUICtrlCreateInput("", 570, 30, 180, 30)
GUICtrlSetTip(-1, "Can be full or partial of the name you want to find, " & @CRLF & "but cannot include driver name and backlash")
$DriverName = GUICtrlCreateLabel(" Driver:", 20, 30, 60, 20)
$FolderDepthLabel = GUICtrlCreateLabel("Folder Depth:", 160, 30, 100, 20)
$FolderDepth = GUICtrlCreateInput("5", 260, 30, 40, 20)
$DriverCombo = GUICtrlCreateCombo("", 90, 30, 50, 22)
$AllDisk = DriveGetDrive("all")
Dim $AllEnableDisk[1] = [0];all enabled disks
For $i = 1 To $AllDisk[0]
    If DriveStatus($AllDisk[$i]) == "READY" Then
        _ArrayAdd($AllEnableDisk, $AllDisk[$i])
        $AllEnableDisk[0] = $AllEnableDisk[0] + 1
    EndIf
Next
$ShowDisksString = _ArrayToString($AllEnableDisk, "|", 1)
GUICtrlSetData(-1, $ShowDisksString, "C:")
$FolderResult = GUICtrlCreateList("", 30, 100, 780, 174)
$Foldernumber = GUICtrlCreateInput("", 25, 68, 30, 23)
$MatchLabelInput = GUICtrlCreateLabel(" folders matched:", 55, 70, 200, 20)
$ToFind = GUICtrlCreateButton("Find!", 370, 70, 90, 30)
$MandatoryToFind = GUICtrlCreateButton("FullyFind!", 370, 35, 90, 30)
GUICtrlSetTip(-1, "completely search the disk, you must click Find!" & @CRLF & " button after pressing this button.")
$HideWindow = GUICtrlCreateButton("Hide Window", 370, 280, 90, 30)
GUISetState()
Dim $AllFolderList[1] = [1]
Dim $DiskFolderWithDirArray[$AllEnableDisk[0] + 1][$MaxFolderInOneDisk]
Dim $DiskFolderWithoutDirArray[$AllEnableDisk[0] + 1][$MaxFolderInOneDisk]
$SearchAllDisk = "";it controls which doisk is selected, when no selection, use all disks
If (Not FileExists("E:\FolderIndex")) Then
    DirCreate("E:\FolderIndex")
EndIf
$HowEnDisks = $AllEnableDisk[0] + 1; how many items in $AllEnableDisk
GenerateOrGetFolderArray($SearchAllDisk)
MsgBox(1, "Ready", "You can search Folder now.", 2)
$TimeToHideWindow = 0;first time not to hide the window
;-----------------------------------------------------
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $MandatoryToFind
            Beep(750, 250)
            $YorN = MsgBox(4, "Confirmation Inquiry", "Do you reaaly try to relist all the folders in all disks? It may need 10-30 minutes.")
            If $YorN == 6 Then;if YES is selected, program will scan this disk completely.
                $SearchAllDisk = GUICtrlRead($DriverCombo)
                GenerateOrGetFolderArray($SearchAllDisk);only scan this disk
                Beep(500, 1000)
            EndIf
        Case $msg = $ToFind
            If GUICtrlRead($FolderNameToSearch) <> "" Then
                $UserInputFolderName = GUICtrlRead($FolderNameToSearch)
                $UserInputDriverName = GUICtrlRead($DriverCombo)
                $UserInputFolderDepth = Number(GUICtrlRead($FolderDepth))
                $SearchDriverLocation = _ArraySearch($AllEnableDisk, $UserInputDriverName)
                $HowMany = $DiskFolderWithoutDirArray[$SearchDriverLocation][0]
                Dim $TempArrayWithout[$HowMany];in order to extract the 2-dimension array to use
                For $i = 0 To $HowMany - 1
                    $TempArrayWithout[$i] = $DiskFolderWithoutDirArray[$SearchDriverLocation][$i]
                Next
                Dim $TempArrayWith[$HowMany]
                For $i = 0 To $HowMany - 1
                    $TempArrayWith[$i] = $DiskFolderWithDirArray[$SearchDriverLocation][$i]
                Next
                $ReturnTwoPara = FindFoldersMatched($UserInputFolderName, $TempArrayWithout);find which index the $UserInputFolderName is located in, then return its full name
                GUICtrlSetData($Foldernumber, $ReturnTwoPara[0])
                GUICtrlSetData($FolderResult, "|" & $ReturnTwoPara[1])
                Beep(200, 500)
                $TimeToHideWindow = TimerInit();begin to count how long thw window will hide
            Else
                MsgBox(1, "", "The folder name cannot be empty.")
            EndIf
        Case $msg = $HideWindow
            GUISetState(@SW_HIDE, $OpenFolderTitle)
        Case $msg = $FolderResult
            $retFolderFullName = _GUICtrlListGetText($FolderResult, _GUICtrlListSelectedIndex($FolderResult))
            If ($retFolderFullName == $LB_ERR) Then
                MsgBox(16, "Error", "Unknown error from _GUICtrlListGetText")
            Else
                ShellExecute($retFolderFullName);it can open folder
            EndIf

        ;;;
    EndSelect
    $dif = TimerDiff($TimeToHideWindow);check if it is time to hide window
    If $TimeToHideWindow > 0 And $dif > $IdleTimeToHide Then;when after first time use, if the window is not used for over 10 seconds, it will hide itself.
        GUISetState(@SW_HIDE, $OpenFolderTitle)
    EndIf
WEnd














#endregion --- GuiBuilder generated code End ---
;Find which folder name match with rhe name you try to find, and then use its index to find the full name of the folder.
Func FindFoldersMatched($FolderNameIWantToFind, $DriverToSearchArray)
    ToolTip("Running, please wait.")
    $PositionOfFolder = 0;the index of the folder you want to find in the $FolderNameToOpen array
    Dim $AllFolderSearched[1] = [0]
    $iStart = 0
    While 1
        $PositionOfFolder = _ArraySearch($DriverToSearchArray, $FolderNameIWantToFind, $iStart, 0, 0, True)
        If @error == 6 Or $PositionOfFolder == -1 Then ExitLoop;fail to find the folder name or error occurs
        _ArrayAdd($AllFolderSearched, $TempArrayWith[$PositionOfFolder]);find the full name
        $AllFolderSearched[0] = $AllFolderSearched[0] + 1
        $iStart = $PositionOfFolder + 1;from the nest index to search the folder name
    WEnd
    $FolderFoundInString = _ArrayToString($AllFolderSearched, "|");trasnfer the array to string so that it is easy to display
    $TotalFolderFound = $AllFolderSearched[0];howmany folders found
    $AllFolderNamesList = StringMid($FolderFoundInString, StringInStr($FolderFoundInString, "|") + 1);remove the first element, which is a number
    Dim $ResultFinal[2] = [$TotalFolderFound, $AllFolderNamesList];construct an simple array to return the search result
    ToolTip("");cancel the tooltip
    Return $ResultFinal
EndFunc  ;==>FindFoldersMatched





; list all folders within the specified folder, including all sub-folders
Func ListAllFolder($Folder, $MaxFolderDepth)
    $FolderList = _FileListToArray($Folder, "*", 2);only finf folders
    If IsArray($FolderList) And $FolderList[0] >= 1 Then
        For $j = 1 To $FolderList[0]
            _ArrayAdd($AllFolderList, $Folder & "\" & $FolderList[$j])
            $AllFolderList[0] = $AllFolderList[0] + 1
        Next
    EndIf
    $FolderCountDepth = StringReplace($Folder, "\", "");test how deep of the current folder depth
    $DepthNumber = StringLen($Folder) - StringLen($FolderCountDepth);count the folder depth
    If IsArray($FolderList) And $FolderList[0] >= 1 And $DepthNumber <= $MaxFolderDepth Then
        For $j = 1 To $FolderList[0]
            ListAllFolder($Folder & "\" & $FolderList[$j], $MaxFolderDepth)
        Next
    EndIf
    Return $AllFolderList
EndFunc  ;==>ListAllFolder

;hide or show the window by PAUSE
Func TogglePause()
    Sleep(25)
    If $Paused == 0 Then;toggle the hide or show
        GUISetState(@SW_SHOW, $OpenFolderTitle)
        $TimeToHideWindow = 0;donot let the window hide when you show it.
        $Paused = $Paused + 1
    Else
        GUISetState(@SW_HIDE, $OpenFolderTitle)
        $Paused = $Paused - 1
    EndIf
    
EndFunc  ;==>TogglePause




; scan the disks and save the full folders name and patial names into TXT file.
;when there is no indexfiles saved or $SearchAllDisk is the specified disk
Func GenerateOrGetFolderArray($SearchAllDisk)
    For $j = 1 To $HowEnDisks - 1
        $WhichDriver = $AllEnableDisk[$j]
        $FolderWithDir = $TheFolderToSaveIndexFiles & StringReplace($WhichDriver, ":", "") & "DiskwithIndex.txt";save all folders with directory name
        $FolderWithoutDir = $TheFolderToSaveIndexFiles & StringReplace($WhichDriver, ":", "") & "DiskwithoutIndex.txt";save the folders without the directory name
        If (Not FileExists($FolderWithDir)) Or (Not FileExists($FolderWithoutDir)) Or $SearchAllDisk == $WhichDriver Then
            $CurrentDiskFolder = ListAllFolder($WhichDriver, $MaxFolderDepth)
            ReDim $AllFolderList[1]
            $AllFolderList[0] = 1
            _FileWriteFromArray($FolderWithDir, $CurrentDiskFolder)
            $FoldersNumberInDisk = UBound($CurrentDiskFolder)
            For $r = 0 To $FoldersNumberInDisk - 1
                $DiskFolderWithDirArray[$j][$r] = $CurrentDiskFolder[$r]
            Next ;save the array into a two diension array later it is easy to get it out
        ;extract out the directory from $CurrentDiskFolder
            Dim $FolderNameToOpen[1] = [1];save the folder name without driver and backlash
            If IsArray($CurrentDiskFolder) And $CurrentDiskFolder[0] >= 1 Then
                For $i = 1 To $CurrentDiskFolder[0] - 1
                    $AFolderName = $CurrentDiskFolder[$i]
                    $Position = StringInStr($AFolderName, "\", 0, -1);only find the last backlash position from the right
                    $FolderNameFinal = StringMid($AFolderName, $Position + 1)
                    _ArrayAdd($FolderNameToOpen, $FolderNameFinal)
                    $FolderNameToOpen[0] = $FolderNameToOpen[0] + 1
                Next
            EndIf
            _FileWriteFromArray($FolderWithoutDir, $FolderNameToOpen)
            $FoldersNumberInDisk = UBound($FolderNameToOpen)
            For $r = 0 To $FoldersNumberInDisk - 1
                $DiskFolderWithoutDirArray[$j][$r] = $FolderNameToOpen[$r]
            Next ;save the array into a two diension array later it is easy to get it out
        Else;the files alreay exist
            Dim $TempArray
            _FileReadToArray($FolderWithDir, $TempArray)
            For $r = 0 To UBound($TempArray) - 1
                $DiskFolderWithDirArray[$j][$r] = $TempArray[$r]
            Next
            Dim $TempArray
            _FileReadToArray($FolderWithoutDir, $TempArray)
            For $r = 0 To UBound($TempArray) - 1
                $DiskFolderWithoutDirArray[$j][$r] = $TempArray[$r]
            Next
        EndIf
    Next
EndFunc  ;==>GenerateOrGetFolderArray

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