Sign in to follow this  
Followers 0
storme

Browse for folder - SMART sleep needed (solved)

9 posts in this topic

#1 ·  Posted (edited)

G'day all

I made a script to automate those "browse for folder" prompts that don't have a convenient text box to type into.

The trouble is as each level is expanded there is a delay as the paths are rad from the destination.

On network drives this can take some time AND the time changes.

To try and avoid this I've set a delay(sleep) at each step.

I'd prefer to do it more intelligently by monitoring the dialog but I have no idea what could watched to cheched if the update has been done.

Anyone got any ideas/suggestions?

Thanks

John Morrison

aka

Storm-E

Edited by storme

Share this post


Link to post
Share on other sites



Based on my experience you should add a minimum of 5 seconds of delay when browsing Network Devices.


My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

MY PROJECTS


Active: IRC UDF, WindowEx UDF
Discontinued: GithubBubbleSort UDF

Share this post


Link to post
Share on other sites

Based on my experience you should add a minimum of 5 seconds of delay when browsing Network Devices.

Yeah I was afraid someone would say that. I pushed it out to .5 of a second. Whcih works on my network BUT I had a gut feeling that it woudln't be enough....sigh

It's why I'm hoping someone will come up with a innovative solution and I won't have to slow it down too far.

Thanks for the feedback...if all else fails I'l make it that.... or maybe add it as an option.

Share this post


Link to post
Share on other sites

Wait which "browse for folder" prompts are you talking about? Can i get a picture of one?


My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

MY PROJECTS


Active: IRC UDF, WindowEx UDF
Discontinued: GithubBubbleSort UDF

Share this post


Link to post
Share on other sites

Wait which "browse for folder" prompts are you talking about? Can i get a picture of one?

Sorry I should have siad DIALOG not prompt. If you look at the link in the first msg I've put a small test script there and the script I designed to navigate the "browser for folder" dialogs.

Share this post


Link to post
Share on other sites

I'm totally unfamiliar with the UDFs you are using and I dont have network to test, so forgive me if this is silly.

Well its an attempt anyway.

#include <Array.au3>
#include <GuiTreeView.au3>
;MsgBox(0,"Selected Folder",FileSelectFolder ( "Just a test", "C:\"))
 
_BFF_SelectFolder("C:\users\john")
MsgBox(0, "_BFF_SelectFolder Result", "@error = " & @error)
Exit
; #FUNCTION# ====================================================================================================================
; Name...........: _BFF_SelectFolder
; Description ...: Automates the "Browse for Folder" Dialog so you can specify with a standard path
; Syntax.........: _BFF_SelectFolder($sPath[, $bClickOK = True])
; Parameters ....: $sPath       - Path to select in dialog
;               $bClickOK       - Optional: Click OK button. Default or True then click OK button
; Return values .: Success - returns True
;               Failure - False
;               |@Error  - 1 = "Browse for Folder" dialog not found
;               |@Error  - 2 = Drive letter not in path
;               |@Error  - 3 = unable to locate my computer in tree
;               |@Error  - 4 = unable to locate directory
; Author ........: Storm-E aka John Morrison
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _BFF_SelectFolder($sPath, $bClickOK = True)
Local $asPath ; holds drive and folder section(s)
Sleep(500)
;Get handle of "Browse for Folder" dialog
Local $HWND = ControlGetHandle("Browse for Folder", "", "[CLASS:SysTreeView32; INSTANCE:1]")
If @error Then
  Return SetError(1, 0, "")
EndIf
; get first item - ya gota start somewhere :)
Local $hCurrentItem = _GUICtrlTreeView_GetFirstItem($HWND)
$hCurrentItem = _GUICtrlTreeView_GetFirstChild($HWND, $hCurrentItem) ; items under desktop
$asPath = StringSplit($sPath, "\")
If $asPath[$asPath[0]] = "" Then $asPath[0] -= 1 ; eliminates blank entry if path has a trailng \
If StringRight($asPath[1], 1) <> ":" Then
  Return SetError(2, 0, "")
EndIf
;Find My Computer
Local $hCurrentItemChild = _GUICtrlTreeView_GetFirstChild($HWND, $hCurrentItem) ; get items child
While StringRight(_GUICtrlTreeView_GetText($HWND, $hCurrentItemChild), 2) <> ":)"
  $hCurrentItem = _GUICtrlTreeView_GetNextSibling($HWND, $hCurrentItem) ; Step to next item
  If $hCurrentItem = 0 Then
   ;Ran out of items so didn't find my computer
   Return SetError(3, 0, "")
  EndIf
  $hCurrentItemChild = _GUICtrlTreeView_GetFirstChild($HWND, $hCurrentItem)
WEnd
_GUICtrlTreeView_Expand($HWND, $hCurrentItem)
_GUICtrlTreeView_ClickItem($HWND, $hCurrentItem)
Do
  $next = _GUICtrlTreeView_GetFirstChild($HWND, $hCurrentItem)
Until $next <> $hCurrentItem
;Sleep(500) ; give time for clickitem to work
;Find drive
$hCurrentItem = $hCurrentItemChild
While StringLeft(StringRight(_GUICtrlTreeView_GetText($HWND, $hCurrentItem), 3), 2) <> $asPath[1]
  $hCurrentItem = _GUICtrlTreeView_GetNextSibling($HWND, $hCurrentItem) ; Step to next item
  If $hCurrentItem = 0 Then
   ;Ran out of items so didn't find my computer
   Return SetError(3, 0, "")
  EndIf
WEnd
;Needed for dialog to update
_GUICtrlTreeView_Expand($HWND, $hCurrentItem)
_GUICtrlTreeView_ClickItem($HWND, $hCurrentItem)
Do
  $next = _GUICtrlTreeView_GetFirstChild($HWND, $hCurrentItem)
Until $next <> $hCurrentItem
;Sleep(500) ; give time for clickitem to work
;Find directory
If $asPath[0] > 1 Then ; Check if only drive was specified
  For $item = 2 To $asPath[0]
   $hCurrentItem = _GUICtrlTreeView_GetFirstChild($HWND, $hCurrentItem)
   _GUICtrlTreeView_Expand($HWND, $hCurrentItem)
   _GUICtrlTreeView_ClickItem($HWND, $hCurrentItem)
   Do
    $next = _GUICtrlTreeView_GetFirstChild($HWND, $hCurrentItem)
   Until $next <> $hCurrentItem
   ;Sleep(500) ; give time for clickitem to work
   While _GUICtrlTreeView_GetText($HWND, $hCurrentItem) <> $asPath[$item]
    $hCurrentItem = _GUICtrlTreeView_GetNextSibling($HWND, $hCurrentItem) ; Step to next item
    If $hCurrentItem = 0 Then
    ;Ran out of items so didn't find directory
    Return SetError(4, 0, "")
    EndIf
   WEnd
   _GUICtrlTreeView_Expand($HWND, $hCurrentItem)
   _GUICtrlTreeView_ClickItem($HWND, $hCurrentItem)
   Do
    $next = _GUICtrlTreeView_GetFirstChild($HWND, $hCurrentItem)
   Until $next <> $hCurrentItem
   ;Sleep(500) ; give time for clickitem to work
  Next
EndIf
;Needed for dialog to update
_GUICtrlTreeView_Expand($HWND, $hCurrentItem)
_GUICtrlTreeView_ClickItem($HWND, $hCurrentItem)
Do
  $next = _GUICtrlTreeView_GetFirstChild($HWND, $hCurrentItem)
Until $next <> $hCurrentItem
;Sleep(700) ; give time for clickitem to work
If $bClickOK Then
  ;Click OK button
  ControlClick("Browse for Folder", "", "[CLASS:Button; INSTANCE:1]")
EndIf
EndFunc   ;==>_BFF_SelectFolder

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

I'm totally unfamiliar with the UDFs you are using and I dont have network to test, so forgive me if this is silly.

Well its an attempt anyway.

Well it's an attmept that WORKS......... AND it speeds it up.. A BIG thanks!!

Now that I see it, it makes sense...

BUT....How did you work out that the "_GUICtrlTreeView_GetFirstChild" would return the current item until the tree expands?

THANKS

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