# How do I select a specific path in SysTreeView32

## 8 posts in this topic

;Hi there I am trying to to search a specific path

c:\Documents and settings\rogers\Local Settings

;the code below work but can someone point how to define the path directly, instead of searching the folder then click to select and so on

; this code below work, it finds each folder click until Local settings

$hWnd5 = WinGetHandle($Title,"")

Sleep(300)
$hlist = ControlGetHandle($hWnd5, "", "SysListView322")
$listid = _GUICtrlListView_FindText($hlist,"Documents and Settings" )
_GUICtrlListView_ClickItem($hlist,$listid, "left", False, 2)
Sleep(100)
$hlist = ControlGetHandle($hWnd5, "", "SysListView322")
$listid = _GUICtrlListView_FindText($hlist,"rogers" )
_GUICtrlListView_ClickItem($hlist,$listid, "left", False, 2)

Sleep(100)
$hlist = ControlGetHandle($hWnd5, "", "SysListView322")
$listid = _GUICtrlListView_FindText($hlist,"Local Settings" )
_GUICtrlListView_ClickItem($hlist,$listid, "left", False, 1)

****************************************************************************************************************************************************************
;This code below does Not work some ideas

;$spath = "C:\" ;$sgettext = ControlTreeView($Title,"","SysTreeView322", "select",$spath)
;$spath = "C:\ | Documents and Settings" ;$sgettext = ControlTreeView($Title,"","SysTreeView322", "select",$spath)
;$spath = "Documents and Settings | rogers" ;$sgettext = ControlTreeView($Title,"","SysTreeView322", "select",$spath)
;$spath = "Documents and Settings | rogers| Local Settings" ;$sgettext = ControlTreeView($Title,"","SysTreeView322", "select",$spath)
;ConsoleWrite($spath &@CRLF) ;$Selectall = ControlListView($hWnd5, "", "SysListView322",$sgettext)
;$Finditem = ControlListView($hWnd5, "", "SysListView322", "Finditem", "Local Settings")
;$Select = ControlListView($hWnd5, "", "SysListView322", "Select",$Finditem) ; consolewrite($Select)

##### Share on other sites

Run('explorer.exe /select, ' & @SystemDir)

Saludos

1 person likes this

Would you like to say thank to Danyfirex using a warmy way?  offer me a cup of coffee...

AutoIt...

##### Share on other sites
;Hi dany,

does work , however the behaviour is not correct. The script  open a new explorer window, which I do not want , see the picture  I want to work in the current window

Run('explorer.exe /select,c:\Documents and settings\rogers\Local Settings') ; open a new explorer windows

##### Share on other sites
I have this code working can someone point me how to delete folder "Test2

include <RecFileListToArray.au3>
#include <WinAPIFiles.au3>

$Ssearch = _RecFileListToArray("c:\Test1\","*.*", 0, 1) For$i = 1 To UBound($Ssearch) - 1 ConsoleWrite($Ssearch[$i] & @CRLF) FileDelete($Ssearch[$i]) ;ConsoleWrite("FileDelete(" &$Ssearch[$i] & ")" & @CRLF) Next here is the result in console I want to delete everthing after Test1 --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop Test2\ Test2\KeyFinderInstaller.exe Test2\results.xml #### Share this post ##### Link to post ##### Share on other sites DirRemove #### Share this post ##### Link to post ##### Share on other sites Not deleting I tried , I am trying to delete Test2 folder with everyting inside #include <RecFileListToArray.au3> #include <WinAPIFiles.au3>$Ssearch = _RecFileListToArray("c:\Test1\","*.*", 0, 1)
Local $deleteDR =$Ssearch
For $i = 1 To UBound($Ssearch) - 1

;FileDelete($Ssearch[$i])
;ConsoleWrite("FileDelete(" & $Ssearch[$i] & ")" & @CRLF)
DirRemove($Ssearch[$i],1)
ConsoleWrite($Ssearch[$i] & @CRLF)
Next

DirRemove($deleteDR,1) **************************************************** console Test2\ Test2\KeyFinderInstaller.exe Test2\results.xml #### Share this post ##### Link to post ##### Share on other sites I found this code orginally from SlimShady and I modify it, works like a charm. Hope it can helps someone. include<File.au3> local$folder1 = "C:\Test1\Test2\" ; this will delete anything after Test2, including folder directory and so on..

_DirRemoveContents($folder1, "*.*") Func _DirRemoveContents($folder,$f) Local$list_of_contents, $status$list_of_contents = _FileListToArray($folder) If IsArray($list_of_contents) Then
If StringRight($folder, 1) <> "\" Then$folder = $folder & "\" If @error = 1 Then Return 1 ; No Files\Folders Found For$a = 1 To $list_of_contents[0] FileSetAttrib($folder & "\" & $list_of_contents[$a], "-RASH")
If StringInStr(FileGetAttrib($folder &$list_of_contents[$a]), "D") Then$status = DirRemove($folder &$list_of_contents[$a], 1) Else$status = FileDelete($folder &$list_of_contents[$a]) EndIf Next Else Return 2 ; Directory doesn't exists EndIf EndFunc ;==>_DirRemoveContents #### Share this post ##### Link to post ##### Share on other sites I found this code orginally from SlimShady and I modify it, works like a charm. Hope it can helps someone. include<File.au3> local$folder1 = "C:\Test1\Test2\" ; this will delete anything after Test2, including folder directory and so on..

_DirRemoveContents($folder1) Func _DirRemoveContents($folder)
Local $list_of_contents,$status
$list_of_contents = _FileListToArray($folder)
If IsArray($list_of_contents) Then If StringRight($folder, 1) <> "\"  Then $folder =$folder & "\"
If @error = 1 Then Return 1 ; No Files\Folders Found
For $a = 1 To$list_of_contents[0]
FileSetAttrib($folder & "\" &$list_of_contents[$a], "-RASH") If StringInStr(FileGetAttrib($folder & $list_of_contents[$a]), "D") Then
$status = DirRemove($folder & $list_of_contents[$a], 1)
Else
$status = FileDelete($folder & $list_of_contents[$a])
EndIf
Next
Else
Return 2 ; Directory doesn't exists
EndIf
EndFunc   ;==>_DirRemoveContents

## Create an account

Register a new account

• ### Similar Content

• By ur
I have an ini file which has structure as below.

And I want to use this value and change only the file name in below path of another ini file.

Can you suggest any approach.

• By Katie_Deely
Hi
Let's say I get a path called "E:\pics\". It has pictures inside which are numbered starting at 0. Then we get something like "E:\pics\0" or "E:\pics\1" or "E:\pics\2"... The amount of numbers, thus the path of the last picture, are known to me already. For example, there are 100 pictures, which means that the files start at 0 and end at 99
However, for some things that isn't enough, because they need the file extension. They can be pretty "random", though. Sometimes it's a JPG, sometimes it's a PNG, sometimes it's a GIF.
So, I know need some kind of function that gets me the file extension, or the complete path, from an incomplete path. The input would be "E:\pics\1" and I expect and output of "E:\pics\1.jpg" for example.
Also, there is just one file extension per number. For example, it there is "E:\pics\1.jpg", there won't be a "E:\pics\1.png" anymore.
And this will be looped as well. First I get number 0, then number 1, then number 2, and so on. So I need something that is able to be repeated in a for-loop without causing problems with the parameters.
Thanks a lot!
How to select a folder and assign the path value to a variable in autoit?

; Selecting a file and assigning that to $sPath value) Case$file $sPath = FileOpenDialog("Open a file", @desktopdir, "Cabinet Files (*.cab)",$FD_MULTISELECT) GUICtrlSetData($file,$sPath) ; How to do the same with a folder? Case $folder$sPath = FileSelectFolder($sPath, "") Need the selected folder path to be used in the$sPath section for further implementation.
Or a method to Select Folder or Files at once.
• By tremolux66
I'm automating a commercial app that will copy files/folders from an optical disc to a folder on a hard drive, and am unable to check an item in a SysTreeView32 control in the app's main window. The disc and its top-level folders are displayed as a simple tree, and I've written a test script that probes and manipulates the control by calling ControlTreeView(). The script cannot, on its own, check the desired item in the TreeView, but it can check the item with some manual intervention. I need to know if there's something missing, or if a different approach is needed.
The operations currently being tested are:
Waiting until the contents of the TreeView control appear before proceeding (the app can take a long time to display the control contents), and Checking the first item's checkbox (i.e., the disc itself), thus selecting the entire disc contents for copying. The test script can complete the first operation successfully, but not the second: there is a side-effect of the first that apparently causes the second one to fail.
When the control's contents eventually become visible, they look like this; note the position of the scrollbar:

The wait is done by repeatedly selecting the first item until @error=0 using the following code fragment (note: the code has been edited for brevity and to remove certain information):
; Wait for the DM window to become active ; -- _WinWaitActivate() is from AU3 Recorder-generated code $hWnd1 = _WinWaitActivate($sDMtitle,"") ; Wait for the SysTreeViewList32 control to display its first item $sCtrlAdvMode = "[CLASS:SysTreeView32; INSTANCE:1]"$i = 0 $iRetVal = ControlTreeView($hWnd1,"",$sCtrlAdvMode,"Select","#0")$iAtError = @error While $iAtError <> 0$i += 1 If $i > 20 Then ExitLoop Sleep(5000)$iRetVal = ControlTreeView($hWnd1,"",$sCtrlAdvMode,"Select","#0") $iAtError = @error WEnd If$i > 20 Then ConsoleWrite("Select: Unable to select 1st item after 20 tries" & @CRLF) This works - the script successfully loops until the contents are visible, but when the item selection finally succeeds, the control contents scroll horizontally, hiding the checkboxes:

The script then tries to check the first item by calling ControlTreeView() from the following code fragment (again, edited for brevity, etc.):
; Check the first item $iRetVal = ControlTreeView($hWnd1,"",$sCtrlAdvMode,"Check","#0") If @error <> 0 Then ConsoleWrite("Check: Unable to check 1st item, return=" &$iRetVal & ", @error=" & @error & ", @extended=" & @extended & @CRLF) $iRetVal = ControlTreeView($hWnd1,"",$sCtrlAdvMode,"IsChecked","#0") ConsoleWrite("IsChecked: return=" &$iRetVal & ", @error=" & @error & ", @extended=" & @extended & @CRLF) The Check call always returns @error=1, and the IsChecked call returns without error, but with a value of False. (The boxes remain unchecked on the screen as well.)
HOWEVER: With some experimentation I discovered that if I put a pause in the test script so that I can manually scroll the TreeView to make the checkboxes visible, then the Check call works - the boxes in the control are all checked, and the IsChecked call returns True.
Any suggestions for making this work under program control (no manual intervention)? The application needs to be completely automated.
Note: I have tried another method for the wait-loop (getting the first item's checkbox value), hoping it would achieve the desired result without scrolling the tree. However, the IsChecked call returns with @error=0 (and False) on the first call, long before the tree was visible.

• By Mecano
Hallo Members,
I'm looking for a good regex to get the drive letter and the last two folders from a file path,
If the path is to long for the label width then show drive +   ellipses and two last folders.
Drive:\(ellipses)\folder\folder
ex. D:\...\folder\folder
and when the folder is in the root of the drive then show D:\Folder

The test GUI
#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.12.0 Author: Mecano Script Function: ELLIPSIS Long path: Drive:\...\Folder\Folder if root then Drive:\Folder #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here $sFile = "F:\Just a folder\in a another folder\and another\This-dir\And-this-dir"$EllipsisPath = StringRegExpReplace($sFile, '\w[a-zA-Z \\]+\\', '') ; <- This needs another regex ;no ellipsis needed, for testing purposes only$sUSB = "K:\Just a folder" $PathforUSB = StringRegExpReplace($sUSB, '\w[a-zA-Z \\]+\\', '') #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Drive + Two last folders of path", 327, 236, 192, 124)$Button1 = GUICtrlCreateButton("Test label", 40, 168, 97, 33) $Label1 = GUICtrlCreateLabel("F:\...\This-dir\And-this-dir", 40, 12, 200, 40) ; <- Looks good but not dynamic GUICtrlSetColor($Label1, 32768) $Label2 = GUICtrlCreateLabel($sFile, 40, 40, 200, 40, $DT_END_ELLIPSIS) ; <- not the last two directorys GUICtrlSetColor($Label2, 16711680) $Label3 = GUICtrlCreateLabel("Var label1", 40, 72, 200, 40) GUICtrlSetColor($Label3, 16711680) $Label4 = GUICtrlCreateLabel("Var label", 40, 104, 200, 40) GUICtrlSetColor($Label4, 16711680) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch$nMsg Case $GUI_EVENT_CLOSE Exit Case$Button1 GUICtrlSetData($Label3,$EllipsisPath) ; $DT_END_ELLIPSIS <- works only on GUICtrlCreateLabel GUICtrlSetData($Label4, \$PathforUSB) EndSwitch WEnd