Jump to content
Sign in to follow this  
farhan879

Search Functions

Recommended Posts

farhan879

Hey guys, i'm creating a GUI. It's almost complete. Its just that i wanna add a search function to it, like you type which file to need to find and hit enter, then several number of files that is related to that keyword comes out. I just installed autoit recently so please help me. Thank you.

Edited by farhan879

System task ---> My first GUICalculator v1.0 ---> My version of the calculatorNetZilla 1.0 --> Web browserEmail Sender --> You can Send emails with this without opening a web browser

Share this post


Link to post
Share on other sites
martin

And yes, the function is something like Run.

The function is something like Run? Maybe you need to look up Walk. :P You definitely need to master that before you Run.

If you have almost completed your gui then there must be a lot more information you could give. If you learnt how to make a gui then you should be able to learn how to use the controls you have used. For me your question is much too vague. I would prefer something more specific and something which indicates you have tried something. If you haven't tried anything then you need to spend some time reading the help.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
farhan879

I've tried but no answer to my question. And about the Run, i meant. press start, on the right hand corner, you'll see a run. Get it?


System task ---> My first GUICalculator v1.0 ---> My version of the calculatorNetZilla 1.0 --> Web browserEmail Sender --> You can Send emails with this without opening a web browser

Share this post


Link to post
Share on other sites
MrCreatoR

You need to search for some files on the hard dtive? look at the FileFindFirstFile() and FileFindNextFile() in the help file :P


 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites
farhan879

I'm not exactly looking for that. I want something like you have to type something and press search. And, i'm not looking for files in the hardrive. I'm trying to make a script that is convienient to use and you don't have to search everywherer. :P

Edited by farhan879

System task ---> My first GUICalculator v1.0 ---> My version of the calculatorNetZilla 1.0 --> Web browserEmail Sender --> You can Send emails with this without opening a web browser

Share this post


Link to post
Share on other sites
MrCreatoR

I'm not exactly looking for that. I want something like you have to type something and press search. And, i'm not looking for files in the hardrive. I'm trying to make a script that is convienient to use and you don't have to search everywherer. :(

Hm... you lost me here. I really can't understand why you need that, but here is a box with input and Search button :P :

#include <GuiConstantsEx.au3>

$GUI = GUICreate("Test Script", 300, 100)

$Input = GUICtrlCreateInput("Test", 20, 20, 260, 20)

$Search_Button = GUICtrlCreateButton("Search", 20, 50, 60, 20)

GUISetState(@SW_SHOW, $GUI)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Search_Button
            MsgBox(64, "", "Search: " & GUICtrlRead($Input))
    EndSwitch
WEnd

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites
farhan879

I need a search function. Its something that you type and press search, several files appear according the keyword. I'm sorry if i'm causing inconvienience for all of you..

Edited by farhan879

System task ---> My first GUICalculator v1.0 ---> My version of the calculatorNetZilla 1.0 --> Web browserEmail Sender --> You can Send emails with this without opening a web browser

Share this post


Link to post
Share on other sites
MrCreatoR

I need a search function. Its something that you type and press search, several files appear according the keyword. I'm sorry if i'm causing inconvienience for all of you..

You will have to explain a little bit better, sorry. You saing that you don't need to search for files, then what you need to search? what files should to appear, and finaly, where they should appear? :P

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites
farhan879

Okay, forget about what i said about i don't need to search the files.

1) I type a name of a file or a name of a pogram.

2) I click the search button.

3) I wait untill it loads finish.

4) Several files appear according to the closest meaning of the word i type.

The files appear below the text i type, or a new window. Anyway you want as long as i am able to search and browse the files.

I hope you get it now. :( Sorry if my english is not good. :P

Edited by farhan879

System task ---> My first GUICalculator v1.0 ---> My version of the calculatorNetZilla 1.0 --> Web browserEmail Sender --> You can Send emails with this without opening a web browser

Share this post


Link to post
Share on other sites
YellowLab

Search algorithms are the things companies are made of: Google, Yahoo.

You might want to look at StringRegExp in the help file.

Bob


You can't see a rainbow without first experiencing the rain.

Share this post


Link to post
Share on other sites
MrCreatoR

@farhan879

Have you tried to do this by yourself? what you got for now, post here and tell as where you have difficulties in the script.


 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites
farhan879

@Yellowlab

Its not what i'm looking for :P

@MrCreator

Here's my script code.

#cs ----------------------------------------------------------------------------

 File Version: V1.0
 Author:       Farhan

 Script Function: Access to pograms
(c) Farhan 2008 All rights reserved.
#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <file.au3>
#include <GUIConstants.au3>

$Form2 = GUICreate("System task", 383, 298, 289, 180)
$Exit = GUICtrlCreateButton("Exit", 128, 248, 89, 25, 0)
$Run_Notepad = GUICtrlCreateButton("Run notepad", 16, 64, 81, 25, 0)
$Run_calculator = GUICtrlCreateButton("Run calculator", 16, 96, 81, 25, 0)
$run_Cmd = GUICtrlCreateButton("Cmd", 256, 96, 75, 25, 0)
$Run_google = GUICtrlCreateButton("Google.com", 256, 64, 75, 25, 0)
$Search = GUICtrlCreateInput("Search", 8, 208, 185, 21)
$Button1 = GUICtrlCreateButton("Search", 216, 208, 75, 17, 0)
$Label1 = GUICtrlCreateLabel("Type a name of a folder, pogram or document.", 8, 184, 222, 17)
GUICtrlSetColor(-1, 0xFFFFFF)
$Browse_button = GUICtrlCreateButton("Browse", 296, 208, 75, 17, 0)
$Group_search = GUICtrlCreateGroup("Search", 0, 168, 377, 81)
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$MenuItem1 = GUICtrlCreateMenu("&File")
$About = GUICtrlCreateMenuItem("about", $MenuItem1)
$Exi = GUICtrlCreateMenuItem("Exit", $MenuItem1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


GUISetBkColor(0x494e48)   ;Sets the background colour

While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
        Case  $msg = $Exit  
             Exit            ;Exits the application when the exit button is pressed
        Case $msg = $Run_Notepad
             Run("notepad.exe");Runs notepad
        Case $msg = $Run_calculator
             Run("calc.exe");Runs calculator
        Case $msg = $About
             MsgBox(64,"About","This system task is created by Farhan as good and convenient application to acccess to your own pogram according to your own needs." & @CRLF & "" & @CRLF & "(c) 2008 farhan879")
        Case $msg = $Exi         
             Exit            ;Exits the application when the exit button is pressed
        Case $msg = $run_Cmd
             Run("cmd.exe");Runs cmd
        Case $msg = $Run_google
             $URL   = "www.google.com"
             $fd        = FileOpen(@TEMPDir & "url.url",2)
             if $fd = -1 Then Exit
             FileWriteLine($fd,"[InternetShortcut]")
             FileWriteLine($fd,"URL=" & $URL)
             FileClose($fd)
             Run(@comspec & " /c " & chr(34) & @TEMPDir & "url.url" & chr(34))      ;Runs default browser           
    EndSelect
WEnd
Edited by farhan879

System task ---> My first GUICalculator v1.0 ---> My version of the calculatorNetZilla 1.0 --> Web browserEmail Sender --> You can Send emails with this without opening a web browser

Share this post


Link to post
Share on other sites
AdmiralAlkex

I want to add the search function but how? :P

That GUI you posted didn't explain anything. Every post you have done so far has been contradicting the others and if you continue like this you are never gonna get some good help. If you really wants some help you need to tell us what you were asked for in post #9. In case you don't understand MrCreatoR here is his questions in other words:

  • Where do you want to search?? (array, harddrive, string etc...)
  • What do you want to search for?? (find a word in a string, find a filename on harddrive etc...)
  • How/where do you want your results?? (array, string, listview etc...)

Share this post


Link to post
Share on other sites
farhan879

1) Folders on your local disk

2) Find a filename your local disk

3) Display the results in list view.

Edited by farhan879

System task ---> My first GUICalculator v1.0 ---> My version of the calculatorNetZilla 1.0 --> Web browserEmail Sender --> You can Send emails with this without opening a web browser

Share this post


Link to post
Share on other sites
MrCreatoR

Here you go:

#include <GuiConstantsEx.au3>
#include <ListViewConstants.au3>

$GUI = GUICreate("Files Search Demo!", 500, 420)

GUICtrlCreateLabel("Path to search:", 20, 5, -1, 15)
$Path_Input = GUICtrlCreateInput("C:\", 20, 20, 460, 20)

GUICtrlCreateLabel("Search request:", 20, 55, -1, 15)
$Request_Input = GUICtrlCreateInput("*.txt", 20, 70, 460, 20)

$Search_Button = GUICtrlCreateButton("Search", 20, 100, 60, 20)
$ListView = GUICtrlCreateListView("Results", 20, 130, 460, 250)

$SearhInfo_Label = GUICtrlCreateLabel("", 110, 105, 370)
$SearhStatus_Label = GUICtrlCreateLabel("", 20, 383, 450, 40)

GUISetState(@SW_SHOW, $GUI)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Search_Button
            $sPath = GUICtrlRead($Path_Input)
            $sRequest = GUICtrlRead($Request_Input)
            
            GUICtrlSendMsg($ListView, $LVM_DELETEALLITEMS, 0, 0)
            GUICtrlSetData($SearhInfo_Label, "Please wait, seaching...")
            
            $aResults = _FileSearch($sPath, $sRequest, 1, 0, $SearhStatus_Label)
            
            If @error Then
                MsgBox(48, "Attention!", "No files found.", 0, $GUI)
            Else
                For $i = 1 To UBound($aResults)-1
                    GUICtrlCreateListViewItem($aResults[$i], $ListView)
                Next
                
                GUICtrlSendMsg($ListView, $LVM_SETCOLUMNWIDTH, 0, -1)
            EndIf
            
            GUICtrlSetData($SearhStatus_Label, "")
            GUICtrlSetData($SearhInfo_Label, StringFormat("Done: %i files found.", UBound($aResults)-1))
    EndSwitch
WEnd

;================================================================================
;Flag = 1 search with recurse
;Flag <> 1 search without recurse
;
;$iRet = 1 return parent directory of the file path
;$iRet <> 1 return full file path
;
;$iStatus_CtrlID - If this is an id of the label control, the function will set the current status of the search
;
;On Failure set @error as following:
;   1 - $sPath is not a dir or it not exists (in this case returned -1).
;   2 - $sPath is empty dir.
;   3 - No files found in $sPath dir.
;
;On Seccess return an array with found files.
;================================================================================
Func _FileSearch($sPath, $sMask, $iFlag=0, $iRet=0, $iStatus_CtrlID=0)
    If Not StringInStr(FileGetAttrib($sPath), "D") Then Return SetError(1, 0, -1)
    
    Local $aRetPathArr[1], $sFindNextFile, $sCurrentPath, $aSubDirFindArr
    If StringInStr($sMask, "*") Then $sMask = StringReplace($sMask, "*.", "")
    
    $sPath = StringRegExpReplace($sPath, '\\+ *$', '\')
    
    Local $hSearch = FileFindFirstFile($sPath & "\*.*")
    If @error = 1 Then Return SetError(2, 0, 0)
    If $hSearch = -1 Then Return SetError(3, 0, 0)
    
    While 1
        $sFindNextFile = FileFindNextFile($hSearch)
        If @error = 1 Then ExitLoop
        
        If $iStatus_CtrlID Then _GUICtrlSetData($iStatus_CtrlID, $sPath)
        
        $sCurrentPath = $sPath & "\" & $sFindNextFile
        
        If $iFlag = 1 And StringInStr(FileGetAttrib($sCurrentPath), "D") Then
            $aSubDirFindArr = _FileSearch($sCurrentPath, $sMask, $iFlag, 0, $iStatus_CtrlID)
            If @error Then ContinueLoop
            
            For $i = 1 To $aSubDirFindArr[0]
                $aRetPathArr[0] += 1
                ReDim $aRetPathArr[$aRetPathArr[0]+1]
                
                $aRetPathArr[$aRetPathArr[0]] = $aSubDirFindArr[$i]
                If $iRet = 1 Then _
                    $aRetPathArr[$aRetPathArr[0]] = StringRegExpReplace($aRetPathArr[$aRetPathArr[0]], "\\[^\\]*$", "")
                
                If $iStatus_CtrlID Then _GUICtrlSetData($iStatus_CtrlID, $aSubDirFindArr[$i])
            Next
        Else
            If $sMask = "*" Or $sFindNextFile = $sMask Or StringRegExpReplace($sCurrentPath, '^.*\.', '') = $sMask Then
                $aRetPathArr[0] += 1
                ReDim $aRetPathArr[$aRetPathArr[0]+1]
                
                $aRetPathArr[$aRetPathArr[0]] = $sCurrentPath
                If $iRet = 1 Then $aRetPathArr[$aRetPathArr[0]] = $sPath
            EndIf
        EndIf
    WEnd
    
    FileClose($hSearch)
    
    If $aRetPathArr[0] = 0 Then Return SetError(3, 0, 0)
    
    Return $aRetPathArr
EndFunc

Func _GUICtrlSetData($iCtrlID, $sData)
    If GUICtrlRead($iCtrlID) <> $sData Then GUICtrlSetData($iCtrlID, $sData)
EndFunc

:P

Edited by MrCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites
BrettF

Share this post


Link to post
Share on other sites
farhan879

Here you go:

#include <GuiConstantsEx.au3>
#include <ListViewConstants.au3>

$GUI = GUICreate("Files Search Demo!", 500, 420)

GUICtrlCreateLabel("Path to search:", 20, 5, -1, 15)
$Path_Input = GUICtrlCreateInput("C:\", 20, 20, 460, 20)

GUICtrlCreateLabel("Search request:", 20, 55, -1, 15)
$Request_Input = GUICtrlCreateInput("*.txt", 20, 70, 460, 20)

$Search_Button = GUICtrlCreateButton("Search", 20, 100, 60, 20)
$ListView = GUICtrlCreateListView("Results", 20, 130, 460, 250)

$SearhInfo_Label = GUICtrlCreateLabel("", 110, 105, 370)
$SearhStatus_Label = GUICtrlCreateLabel("", 20, 383, 450, 40)

GUISetState(@SW_SHOW, $GUI)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Search_Button
            $sPath = GUICtrlRead($Path_Input)
            $sRequest = GUICtrlRead($Request_Input)
            
            GUICtrlSendMsg($ListView, $LVM_DELETEALLITEMS, 0, 0)
            GUICtrlSetData($SearhInfo_Label, "Please wait, seaching...")
            
            $aResults = _FileSearch($sPath, $sRequest, 1, 0, $SearhStatus_Label)
            
            If @error Then
                MsgBox(48, "Attention!", "No files found.", 0, $GUI)
            Else
                For $i = 1 To UBound($aResults)-1
                    GUICtrlCreateListViewItem($aResults[$i], $ListView)
                Next
                
                GUICtrlSendMsg($ListView, $LVM_SETCOLUMNWIDTH, 0, -1)
            EndIf
            
            GUICtrlSetData($SearhStatus_Label, "")
            GUICtrlSetData($SearhInfo_Label, StringFormat("Done: %i files found.", UBound($aResults)-1))
    EndSwitch
WEnd

;================================================================================
;Flag = 1 search with recurse
;Flag <> 1 search without recurse
;
;$iRet = 1 return parent directory of the file path
;$iRet <> 1 return full file path
;
;$iStatus_CtrlID - If this is an id of the label control, the function will set the current status of the search
;
;On Failure set @error as following:
;   1 - $sPath is not a dir or it not exists (in this case returned -1).
;   2 - $sPath is empty dir.
;   3 - No files found in $sPath dir.
;
;On Seccess return an array with found files.
;================================================================================
Func _FileSearch($sPath, $sMask, $iFlag=0, $iRet=0, $iStatus_CtrlID=0)
    If Not StringInStr(FileGetAttrib($sPath), "D") Then Return SetError(1, 0, -1)
    
    Local $aRetPathArr[1], $sFindNextFile, $sCurrentPath, $aSubDirFindArr
    If StringInStr($sMask, "*") Then $sMask = StringReplace($sMask, "*.", "")
    
    $sPath = StringRegExpReplace($sPath, '\\+ *$', '\')
    
    Local $hSearch = FileFindFirstFile($sPath & "\*.*")
    If @error = 1 Then Return SetError(2, 0, 0)
    If $hSearch = -1 Then Return SetError(3, 0, 0)
    
    While 1
        $sFindNextFile = FileFindNextFile($hSearch)
        If @error = 1 Then ExitLoop
        
        If $iStatus_CtrlID Then _GUICtrlSetData($iStatus_CtrlID, $sPath)
        
        $sCurrentPath = $sPath & "\" & $sFindNextFile
        
        If $iFlag = 1 And StringInStr(FileGetAttrib($sCurrentPath), "D") Then
            $aSubDirFindArr = _FileSearch($sCurrentPath, $sMask, $iFlag, 0, $iStatus_CtrlID)
            If @error Then ContinueLoop
            
            For $i = 1 To $aSubDirFindArr[0]
                $aRetPathArr[0] += 1
                ReDim $aRetPathArr[$aRetPathArr[0]+1]
                
                $aRetPathArr[$aRetPathArr[0]] = $aSubDirFindArr[$i]
                If $iRet = 1 Then _
                    $aRetPathArr[$aRetPathArr[0]] = StringRegExpReplace($aRetPathArr[$aRetPathArr[0]], "\\[^\\]*$", "")
                
                If $iStatus_CtrlID Then _GUICtrlSetData($iStatus_CtrlID, $aSubDirFindArr[$i])
            Next
        Else
            If $sMask = "*" Or $sFindNextFile = $sMask Or StringRegExpReplace($sCurrentPath, '^.*\.', '') = $sMask Then
                $aRetPathArr[0] += 1
                ReDim $aRetPathArr[$aRetPathArr[0]+1]
                
                $aRetPathArr[$aRetPathArr[0]] = $sCurrentPath
                If $iRet = 1 Then $aRetPathArr[$aRetPathArr[0]] = $sPath
            EndIf
        EndIf
    WEnd
    
    FileClose($hSearch)
    
    If $aRetPathArr[0] = 0 Then Return SetError(3, 0, 0)
    
    Return $aRetPathArr
EndFunc

Func _GUICtrlSetData($iCtrlID, $sData)
    If GUICtrlRead($iCtrlID) <> $sData Then GUICtrlSetData($iCtrlID, $sData)
EndFunc

:P

Thank you so much! I've been looking for that. Thanks again. :(

System task ---> My first GUICalculator v1.0 ---> My version of the calculatorNetZilla 1.0 --> Web browserEmail Sender --> You can Send emails with this without opening a web browser

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.