Jump to content

Help with FileSelectFolder


Recommended Posts

Hi All,

Man I wish I knew what I was goin'... See I'm a REAL newbie to this scripting thig and I'm tryin' to mod this code and trap this nasty error, glitch, etc., whatever it is. If you cancel the routine (FileSelectFolder) it returns an @error 1, ok I got that. But then it clears the path ($location) and if the user then presses "Start Search", script hangs for a while then searches the C Drive (I think... somethin' like that...) But what I need it to do, is return to a previous state before the user even launched that routine... with me? Anyway if someone, anyone could PUSH me in the right direction, I'd most likely name my first born after ya...

Oh, BTW, please ignore commects in code, (there only there to help me out with what is happenen.)

Thanks a ton in advance!

BBB

#include <GuiConstants.au3>

;

Dim $WindowWidth; MAY NOT NEED THIS

;

;==========================================

; Splash Screen

;==========================================

;

$banner = "splash2.jpg" ; Banner File

SplashImageOn("", $banner,500, 148)

Sleep(5000) ; wait for the image to display 5 seconds.

;SplashOff() ; turn the splash off.

;

;******************************************

;I have elected to turn off Splash AFTER

;First Search

;******************************************

;

;==========================================

;

;

;==========================================

; Create The GUI

;==========================================

;

GUICreate("", 400, 400)

;

;==========================================

; Picture Banner

;==========================================

;

GuiCtrlCreatePic("titlebar.jpg",0,0, 400,80)

;

;==========================================

;==========================================

;

;==========================================

; Default File Search Path

; READ ONLY - MUST BROWSE

;==========================================

;

$defaultpath = ("C:\Program Files\AutoIt3\Examples"); for error trap

$location = GUICtrlCreateInput("C:\Program Files\AutoIt3\Examples", 30, 100, 200, 20, $ES_READONLY)

;

;==========================================

; Browse Button

;==========================================

$browse_btn = GUICtrlCreateButton("Browse Folders", 260, 100, 110, 20)

;

;

$word_search = GUICtrlCreateInput(".au3", 30, 130, 200, 20)

$go_btn = GUICtrlCreateButton("Start Search", 260, 130, 110, 20)

GUICtrlSetState(-1, $GUI_DEFBUTTON)

$Edit1 = GUICtrlCreateList("Found File list", 30, 170, 340, 100, $WS_HSCROLL)

GUICtrlSetLimit(-1,600); to limit horizontal scrolling

;

;

;$Edit1 = GUICtrlCreateList("Found File list", 30, 170, 340, 100)

;

;

$label = GUICtrlCreateLabel("Files Found with Phrase: None", 205, 330, 220, 20)

$label2 = GUICtrlCreateLabel("Searched Files: None", 30, 330, 120, 20)

$view_btn = GUICtrlCreateButton("View File", 185, 350, 80, 20)

$Search_btn = GUICtrlCreateButton("View All", 40, 350, 80, 20)

$SciTE_btn = GUICtrlCreateButton("Open in SciTE", 285, 350, 80, 20)

;

;==========================================

; 1st search

;==========================================

$Found = 0

$Searched = 0

GUICtrlSetData($label, "Files Found with Phrase: " & $Found)

GUICtrlSetData($Edit1, "")

$Temp_Dir = (GUICtrlRead($location))

If StringRight($Temp_Dir, 1) <> "\" Then $Temp_Dir = $Temp_Dir & "\"

$Temp_File = "*.au3"

$Temp_Word = (GUICtrlRead($word_search))

RunWait(@ComSpec & ' /c ' & 'dir "' & $Temp_Dir & $Temp_File & '" /a :h /b /s' & ' > "' & @TempDir & '\au3.txt"', '', @SW_HIDE)

$hFile = FileOpen(@TempDir & "\au3.txt", 0)

While 1

$sLine = FileReadLine($hFile)

If @error = -1 Then ExitLoop

$Temp_Dir = $sLine

$Temp_Search = FileRead($sLine, FileGetSize($sLine))

If StringInStr($Temp_Search, $Temp_Word) Then

GUICtrlSetData($Edit1, $sLine, 1)

$Found = $Found + 1

GUICtrlSetData($label, "Files Found with Phrase: " & $Found)

EndIf

$Searched = $Searched + 1

GUICtrlSetData($label2, "Searched Files: " & $Searched)

WEnd

SplashOff() ; turn the splash off AFTER search completes.

;

;==========================================

; Code goes here if correct file is found

;==========================================

;

;==========================================

; 2nd search if more than one

;==========================================

GUISetState()

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

Exit

Case $msg = $browse_btn

$find_loc = FileSelectFolder("Choose a folder.", "")

GUICtrlSetData($location, $find_loc)

If @error = -1 Then $location = $defaultpath

Case $msg = $go_btn

search_Folders()

GUICtrlSetState($word_search, $GUI_FOCUS)

Case $msg = $view_btn

view()

Case $msg = $Search_btn

view_all()

Case $msg = $SciTE_btn

open_SciTE()

EndSelect

WEnd

Func search_Folders()

$Found = 0

$Searched = 0

GUICtrlSetData($label, "Files Found with Phrase: " & $Found)

GUICtrlSetData($Edit1, "")

$Temp_Dir = (GUICtrlRead($location))

If StringRight($Temp_Dir, 1) <> "\" Then $Temp_Dir = $Temp_Dir & "\"

$Temp_File = "*.au3"

$Temp_Word = (GUICtrlRead($word_search))

RunWait(@ComSpec & ' /c ' & 'dir "' & $Temp_Dir & $Temp_File & '" /a :h /b /s' & ' > "' & @TempDir & '\au3.txt"', '', @SW_HIDE)

$hFile = FileOpen(@TempDir & "\au3.txt", 0)

While 1

$sLine = FileReadLine($hFile)

If @error = -1 Then ExitLoop

$Temp_Dir = $sLine

$Temp_Search = FileRead($sLine, FileGetSize($sLine))

If StringInStr($Temp_Search, $Temp_Word) Then

GUICtrlSetData($Edit1, $sLine, 1)

$Found = $Found + 1

GUICtrlSetData($label, "Files Found with Phrase: " & $Found)

EndIf

$Searched = $Searched + 1

GUICtrlSetData($label2, "Searched Files: " & $Searched)

WEnd

EndFunc;==>search_Folders

;==========================================

;==========================================

Func view()

;==========================================

; Conversion routine

;==========================================

$Temp_Edit = GUICtrlRead($Edit1)

$Temp_Word = (GUICtrlRead($word_search))

If $Temp_Edit = "" Or $Temp_Edit = "Found File list" Then

;==========================================

; If no file selected display error

;==========================================

MsgBox(48, "ERROR!", "Please select a file to convert.")

Return

EndIf

;==========================================

; Else convert file

;==========================================

Run("notepad.exe " & $Temp_Edit); Opens notepad w/ file

WinWaitActive("")

Sleep(200)

Send("!EF"); opens find

Sleep(200)

Send($Temp_Word, 1); send file search criteria

Sleep(200)

Send("!f"); Find first instance of search criteria

EndFunc;==>view

;==========================================

;==========================================

Func view_all()

;==========================================

; List All routine

;==========================================

Run("notepad.exe " & @TempDir & "\au3.txt")

EndFunc;==>view_all

Func open_SciTE()

$Temp_Edit = GUICtrlRead($Edit1)

If $Temp_Edit = "" Or $Temp_Edit = "Found File list" Then

MsgBox(0, "", "No Files\Folders Selected.")

Return

EndIf

If ProcessExists("SciTE.exe") Then

MsgBox(0, "SciTE is Running", "Placing File in Scite.exe ", 2)

opt("WinTitleMatchMode", 4)

$Temp_Text = FileRead($Temp_Edit, FileGetSize($Temp_Edit))

WinActivate("classname=SciTEWindow")

WinWaitActive("classname=SciTEWindow")

ControlSend("classname=SciTEWindow", "", "", "^n")

Sleep(50)

ControlSetText("classname=SciTEWindow", "", "Scintilla1", $Temp_Text)

opt("WinTitleMatchMode", 1)

Return

EndIf

$Temp_Edit = FileGetShortName($Temp_Edit)

Run(@ComSpec & " /c Start " & $Temp_Edit, "", @SW_HIDE)

EndFunc;==>open_SciTE

Link to comment
Share on other sites

Hi All,

Man I wish I knew what I was goin'... See I'm a REAL newbie to this scripting thig and I'm tryin' to mod this code and trap this nasty error, glitch, etc., whatever it is. If you cancel the routine (FileSelectFolder) it returns an @error 1, ok I got that. But then it clears the path ($location) and if the user then presses "Start Search", script hangs for a while then searches the C Drive (I think... somethin' like that...) But what I need it to do, is return to a previous state before the user even launched that routine... with me? Anyway if someone, anyone could PUSH me in the right direction, I'd most likely name my first born after ya...

Oh, BTW, please ignore commects in code, (there only there to help me out with what is happenen.)

Thanks a ton in advance!

BBB

CODE
#include <GuiConstants.au3>

;

Dim $WindowWidth; MAY NOT NEED THIS

;

;==========================================

; Splash Screen

;==========================================

;

$banner = "splash2.jpg" ; Banner File

SplashImageOn("", $banner,500, 148)

Sleep(5000) ; wait for the image to display 5 seconds.

;SplashOff() ; turn the splash off.

;

;******************************************

;I have elected to turn off Splash AFTER

;First Search

;******************************************

;

;==========================================

;

;

;==========================================

; Create The GUI

;==========================================

;

GUICreate("", 400, 400)

;

;==========================================

; Picture Banner

;==========================================

;

GuiCtrlCreatePic("titlebar.jpg",0,0, 400,80)

;

;==========================================

;==========================================

;

;==========================================

; Default File Search Path

; READ ONLY - MUST BROWSE

;==========================================

;

$defaultpath = ("C:\Program Files\AutoIt3\Examples"); for error trap

$location = GUICtrlCreateInput("C:\Program Files\AutoIt3\Examples", 30, 100, 200, 20, $ES_READONLY)

;

;==========================================

; Browse Button

;==========================================

$browse_btn = GUICtrlCreateButton("Browse Folders", 260, 100, 110, 20)

;

;

$word_search = GUICtrlCreateInput(".au3", 30, 130, 200, 20)

$go_btn = GUICtrlCreateButton("Start Search", 260, 130, 110, 20)

GUICtrlSetState(-1, $GUI_DEFBUTTON)

$Edit1 = GUICtrlCreateList("Found File list", 30, 170, 340, 100, $WS_HSCROLL)

GUICtrlSetLimit(-1,600); to limit horizontal scrolling

;

;

;$Edit1 = GUICtrlCreateList("Found File list", 30, 170, 340, 100)

;

;

$label = GUICtrlCreateLabel("Files Found with Phrase: None", 205, 330, 220, 20)

$label2 = GUICtrlCreateLabel("Searched Files: None", 30, 330, 120, 20)

$view_btn = GUICtrlCreateButton("View File", 185, 350, 80, 20)

$Search_btn = GUICtrlCreateButton("View All", 40, 350, 80, 20)

$SciTE_btn = GUICtrlCreateButton("Open in SciTE", 285, 350, 80, 20)

;

;==========================================

; 1st search

;==========================================

$Found = 0

$Searched = 0

GUICtrlSetData($label, "Files Found with Phrase: " & $Found)

GUICtrlSetData($Edit1, "")

$Temp_Dir = (GUICtrlRead($location))

If StringRight($Temp_Dir, 1) <> "\" Then $Temp_Dir = $Temp_Dir & "\"

$Temp_File = "*.au3"

$Temp_Word = (GUICtrlRead($word_search))

RunWait(@ComSpec & ' /c ' & 'dir "' & $Temp_Dir & $Temp_File & '" /a :h /b /s' & ' > "' & @TempDir & '\au3.txt"', '', @SW_HIDE)

$hFile = FileOpen(@TempDir & "\au3.txt", 0)

While 1

$sLine = FileReadLine($hFile)

If @error = -1 Then ExitLoop

$Temp_Dir = $sLine

$Temp_Search = FileRead($sLine, FileGetSize($sLine))

If StringInStr($Temp_Search, $Temp_Word) Then

GUICtrlSetData($Edit1, $sLine, 1)

$Found = $Found + 1

GUICtrlSetData($label, "Files Found with Phrase: " & $Found)

EndIf

$Searched = $Searched + 1

GUICtrlSetData($label2, "Searched Files: " & $Searched)

WEnd

SplashOff() ; turn the splash off AFTER search completes.

;

;==========================================

; Code goes here if correct file is found

;==========================================

;

;==========================================

; 2nd search if more than one

;==========================================

GUISetState()

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

Exit

Case $msg = $browse_btn

$find_loc = FileSelectFolder("Choose a folder.", "")

GUICtrlSetData($location, $find_loc)

If @error = -1 Then $location = $defaultpath

Case $msg = $go_btn

search_Folders()

GUICtrlSetState($word_search, $GUI_FOCUS)

Case $msg = $view_btn

view()

Case $msg = $Search_btn

view_all()

Case $msg = $SciTE_btn

open_SciTE()

EndSelect

WEnd

Func search_Folders()

$Found = 0

$Searched = 0

GUICtrlSetData($label, "Files Found with Phrase: " & $Found)

GUICtrlSetData($Edit1, "")

$Temp_Dir = (GUICtrlRead($location))

If StringRight($Temp_Dir, 1) <> "\" Then $Temp_Dir = $Temp_Dir & "\"

$Temp_File = "*.au3"

$Temp_Word = (GUICtrlRead($word_search))

RunWait(@ComSpec & ' /c ' & 'dir "' & $Temp_Dir & $Temp_File & '" /a :h /b /s' & ' > "' & @TempDir & '\au3.txt"', '', @SW_HIDE)

$hFile = FileOpen(@TempDir & "\au3.txt", 0)

While 1

$sLine = FileReadLine($hFile)

If @error = -1 Then ExitLoop

$Temp_Dir = $sLine

$Temp_Search = FileRead($sLine, FileGetSize($sLine))

If StringInStr($Temp_Search, $Temp_Word) Then

GUICtrlSetData($Edit1, $sLine, 1)

$Found = $Found + 1

GUICtrlSetData($label, "Files Found with Phrase: " & $Found)

EndIf

$Searched = $Searched + 1

GUICtrlSetData($label2, "Searched Files: " & $Searched)

WEnd

EndFunc;==>search_Folders

;==========================================

;==========================================

Func view()

;==========================================

; Conversion routine

;==========================================

$Temp_Edit = GUICtrlRead($Edit1)

$Temp_Word = (GUICtrlRead($word_search))

If $Temp_Edit = "" Or $Temp_Edit = "Found File list" Then

;==========================================

; If no file selected display error

;==========================================

MsgBox(48, "ERROR!", "Please select a file to convert.")

Return

EndIf

;==========================================

; Else convert file

;==========================================

Run("notepad.exe " & $Temp_Edit); Opens notepad w/ file

WinWaitActive("")

Sleep(200)

Send("!EF"); opens find

Sleep(200)

Send($Temp_Word, 1); send file search criteria

Sleep(200)

Send("!f"); Find first instance of search criteria

EndFunc;==>view

;==========================================

;==========================================

Func view_all()

;==========================================

; List All routine

;==========================================

Run("notepad.exe " & @TempDir & "\au3.txt")

EndFunc;==>view_all

Func open_SciTE()

$Temp_Edit = GUICtrlRead($Edit1)

If $Temp_Edit = "" Or $Temp_Edit = "Found File list" Then

MsgBox(0, "", "No Files\Folders Selected.")

Return

EndIf

If ProcessExists("SciTE.exe") Then

MsgBox(0, "SciTE is Running", "Placing File in Scite.exe ", 2)

opt("WinTitleMatchMode", 4)

$Temp_Text = FileRead($Temp_Edit, FileGetSize($Temp_Edit))

WinActivate("classname=SciTEWindow")

WinWaitActive("classname=SciTEWindow")

ControlSend("classname=SciTEWindow", "", "", "^n")

Sleep(50)

ControlSetText("classname=SciTEWindow", "", "Scintilla1", $Temp_Text)

opt("WinTitleMatchMode", 1)

Return

EndIf

$Temp_Edit = FileGetShortName($Temp_Edit)

Run(@ComSpec & " /c Start " & $Temp_Edit, "", @SW_HIDE)

EndFunc;==>open_SciTE

I'm not sure I understand your question exactly, but you can read the data from a control and save it to a variable, then set the data back to the control later. Is that anything like what you meant? :lmao:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I'm not sure I understand your question exactly, but you can read the data from a control and save it to a variable, then set the data back to the control later. Is that anything like what you meant? :lmao:

Thanks for the reply PsaltyDS,

I'm not really sure... I'm VERY new to scripting. I have some experience with Basic (remember that old dog) and was at one time "ok" with batch. This script is pretty much what I need it to do except, (I'm a Land Surveyor, the guys I work with are not the sharpest tools in the shed), I need the script to "goto" start "If" the user presses the "Cancel" button during the FileSelectFolder routine,

(BTW, How do you insert "Code" here?)

Case $msg = $browse_btn

$find_loc = FileSelectFolder("Choose a folder.", "")

GUICtrlSetData($location, $find_loc)

But instead, FileSelectFolder, clears the path and (that's not a problem yet), If the user then presses the search button, the script hangs for a min. or so then searches the entire drive. I just want the script to go back to "start of script" or whatever (like they never pressed anything).

BTW, I Like bangin' my head against the wall because it feels Sooooo good when I stop.

The help doesn't really explain (and I'm NO programmer) how to deal with this.

Pleeeeeze, help a brother out...

Thanks!

BBB

Link to comment
Share on other sites

Thanks for the reply PsaltyDS,

I'm not really sure... I'm VERY new to scripting. I have some experience with Basic (remember that old dog) and was at one time "ok" with batch. This script is pretty much what I need it to do except, (I'm a Land Surveyor, the guys I work with are not the sharpest tools in the shed), I need the script to "goto" start "If" the user presses the "Cancel" button during the FileSelectFolder routine,

(BTW, How do you insert "Code" here?)

Case $msg = $browse_btn

$find_loc = FileSelectFolder("Choose a folder.", "")

GUICtrlSetData($location, $find_loc)

But instead, FileSelectFolder, clears the path and (that's not a problem yet), If the user then presses the search button, the script hangs for a min. or so then searches the entire drive. I just want the script to go back to "start of script" or whatever (like they never pressed anything).

BTW, I Like bangin' my head against the wall because it feels Sooooo good when I stop.

The help doesn't really explain (and I'm NO programmer) how to deal with this.

Pleeeeeze, help a brother out...

Thanks!

BBB

This is the line in your script that makes it search the whole drive:

If StringRight($Temp_Dir, 1) <> "\" Then $Temp_Dir = $Temp_Dir & "\"

That line makes sure any path entered will start with a backslash, so if the path is blank, you wind up with just "\".

The path is initialized by this line:

$location = GUICtrlCreateInput("C:\Program Files\AutoIt3\Examples", 30, 100, 200, 20, $ES_READONLY)

I would change that like this:

$InitialLoc = "C:\Program Files\AutoIt3\Examples"
$location = GUICtrlCreateInput($InitialLoc, 30, 100, 200, 20, $ES_READONLY)

That way you have the default path saved as $InitialLoc to put back later. Add a line before the first one I mentioned to put the default path back if it's blank:

If $Temp_Dir = "" Then $Temp_Dir = $InitialLoc
    If StringRight($Temp_Dir, 1) <> "\" Then $Temp_Dir = $Temp_Dir & "\"

When editing messages on this board, the code boxes are created by highlighting text and then click the "#" icon above the edit box.

Hope that helps! :lmao:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

This is the line in your script that makes it search the whole drive:

If StringRight($Temp_Dir, 1) <> "\" Then $Temp_Dir = $Temp_Dir & "\"

That line makes sure any path entered will start with a backslash, so if the path is blank, you wind up with just "\".

The path is initialized by this line:

$location = GUICtrlCreateInput("C:\Program Files\AutoIt3\Examples", 30, 100, 200, 20, $ES_READONLY)

I would change that like this:

$InitialLoc = "C:\Program Files\AutoIt3\Examples"
$location = GUICtrlCreateInput($InitialLoc, 30, 100, 200, 20, $ES_READONLY)

That way you have the default path saved as $InitialLoc to put back later. Add a line before the first one I mentioned to put the default path back if it's blank:

If $Temp_Dir = "" Then $Temp_Dir = $InitialLoc
    If StringRight($Temp_Dir, 1) <> "\" Then $Temp_Dir = $Temp_Dir & "\"

When editing messages on this board, the code boxes are created by highlighting text and then click the "#" icon above the edit box.

Hope that helps! :lmao:

OMG!!

Thank You! As stated before.. I will name my first born after you... do you favor "Salty" or something a little more personal? Again YOU B THE MAN!!!

BBB

PS Thanks for the "Code" tip, as well.

Link to comment
Share on other sites

OMG!!

Thank You! As stated before.. I will name my first born after you... do you favor "Salty" or something a little more personal? Again YOU B THE MAN!!!

BBB

PS Thanks for the "Code" tip, as well.

Select
     Case $FirstBorn = "Boy"
          $Name = "Linus"
     Case $FirstBorn = "Girl"
          $Name = "Pamela"
     Case Else
          SetError(1)
          Exit
EndSelect

:lmao:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Select
     Case $FirstBorn = "Boy"
          $Name = "Linus"
     Case $FirstBorn = "Girl"
          $Name = "Pamela"
     Case Else
          SetError(1)
          Exit
EndSelect

:lmao:

On Exit
$Name = "Pamela"

Not Correct but you get the idea,

Thanks again!

BBB

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...