Jump to content

Search Files/Folders


Recommended Posts

Hiya,

For sometime now I have been trying to make a program to search through files/folders and display them in a listbox. Here is my GUI:

#include <GUIConstants.au3>

Global $Index = @ScriptDir & '\index.ini' ; Index file

$GUI = GUICreate("GUI", 378, 249, -1, -1)
GUICtrlCreateLabel("Query:", 8, 8, 35, 17)
$Cast = GUICtrlCreateCombo("", 48, 8, 321, 25)
$Files = GUICtrlCreateList("", 8, 40, 361, 201)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

But that's as far as I can get. From the AutoIt I understand I will need to, put all the files and folders in an array and then as the search query is typed, select the files/folders and list them. However I do not know how to go about it.

I really would like to do this.

Thanks, Touch.

[center][font="Arial"]If practise makes perfect and no-ones perfect whats the point of practise?[/font]Sorry for my rude attitude when I started here.[/center]

Link to comment
Share on other sites

Here is something I found in the GUI section, with help of Martin and I forgot his name:

#include <GUIConstants.au3>

Global $_Index, $Data = '', $Split = StringSplit($Data, "|"), $savetext
Dim $buffer

Index()

Opt("GUIDataSeparatorChar", "|")
$split = StringSplit($data, "|")

$GUI = GUICreate("GUI", 378, 265, -1, -1)
GUICtrlCreateLabel("Query:", 8, 8, 35, 17)
$input = GUICtrlCreateInput("", 48, 8, 321, 25)
$list = GUICtrlCreateList("", 8, 40, 361, 201)
GUICtrlSetData(-1, $Data)
$Case = GUICtrlCreateCheckbox("Case Sensitive", 10, 242)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
    If GUICtrlRead($input) <> "" Then
        Search()
        
        Do
            $msg = GUIGetMsg()
            Select
                Case $msg = $GUI_EVENT_CLOSE
                    Exit
                Case Else
            ;;;
            EndSelect
        Until GUICtrlRead($input) <> $savetext
        
        If GUICtrlRead($input) = "" Then
            GUICtrlSetData($list, "")
            GUICtrlSetData($list, $data)
        EndIf
    EndIf
WEnd

Func Index()
    $Folder = @ScriptDir
    $Search = FileFindFirstFile($Folder & '\*.*')
    
    While 1
        $File = FileFindNextFile($Search)
        If @error Then ExitLoop
        $Attr = FileGetAttrib($File)
        If Not @error And StringInStr($Attr, 'D') = 0 Then
            $Data = $Data & '|' & $File
        EndIf
    WEnd
    
    FileClose($Search)

    $Data = StringLeft($Data, StringLen($Data) - 1);remove last separator
    $Data = StringRight($Data, StringLen($Data) - 1);remove first separator
    
    ConsoleWrite($Data & @CRLF); Debug Data (Output)
EndFunc ;==>Index

Func Search()
    $savetext = GUICtrlRead($input)
    For $i = 1 To $Split[0]
        If GUICtrlRead($Case) = $GUI_CHECKED Then
            If StringLeft($Split[$i], StringLen(GUICtrlRead($input))) == $savetext Then
                $buffer &= $Split[$i] & "|"
            EndIf
        Else
            If StringLower(StringLeft($Split[$i], StringLen(GUICtrlRead($input)))) == StringLower($savetext) Then
                $buffer &= $Split[$i] & "|"
            EndIf
        EndIf
    Next
    $buffer = StringTrimRight($buffer, 1)
    GUICtrlSetData($list, "")
    GUICtrlSetData($list, $buffer)
    $buffer = ""
EndFunc ;==>Search

Edit: I changed some code, the GUI and added functions to do the work.

Edited by JamesBrooks
Link to comment
Share on other sites

Here is something I found in the GUI section, with help of Martin and I forgot his name:

SNIP

Thanks James but I need to be able to look through all files and folders, sort of like neoSearch.

[center][font="Arial"]If practise makes perfect and no-ones perfect whats the point of practise?[/font]Sorry for my rude attitude when I started here.[/center]

Link to comment
Share on other sites

Thanks James but I need to be able to look through all files and folders, sort of like neoSearch.

Make a script wich runs this in cmd "cd C:\" and then "dir /s /b >list.txt" so it will create a list of allll files in the C drive. Then you can easily navigate through them.

Pls tell me if it was helpful :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...