Jump to content

Getting path when browsing?


Recommended Posts

The problem is, as you can see in the script, when pressing the first folders in the tree, is writes the path in the Input obove.. but when clicking on subfolders, it should write the new path, including the upper folder - witch it dosen't.

How can i possibly retrive the path when browsing trogh this tree, ive been working on it for weeks, and can't get any solution at all!

#include <GUIConstants.au3>
#include <GuiListView.au3>
Const $LVS_SORTDESCENDING = 0x0020

GUICreate("Treeview Browsing - By FreeKill",750,500)
$MainTree = GUICtrlCreateTreeView(1, 60, 250, 417)
GUICtrlSetImage(-1,"shell32.dll",3,4)
GUICtrlSetImage(-1,"shell32.dll",4,2)
$SubTree = GUICtrlCreateListview("Name|Size|Type|Changed",258, 60, 492, 417)
_GUICtrlListViewSetColumnWidth($SubTree, 0,190)
_GUICtrlListViewSetColumnWidth($SubTree, 1,100)
_GUICtrlListViewSetColumnWidth($SubTree, 2,80)
_GUICtrlListViewSetColumnWidth($SubTree, 3,100)
_GUICtrlListViewJustifyColumn ($SubTree, 1, 1)
_GUICtrlListViewJustifyColumn ($SubTree, 3, 0)
GUICtrlCreateGroup("",0,53,252,425)

$DirInput = GUICtrlCreateInput("C:\",5,10,183,20)
$BrowseBtn = GUICtrlCreateButton("Search",193,10,60,21)
$CurrentPath = GUICtrlCreateInput(GUICtrlRead($DirInput),5,35,247,20)
GUICtrlSetState(-1,$GUI_Disable)
$ObjCount = GUICtrlCreateInput("0 Object(s)",0,480,150,20,$ES_READONLY)
$SpaceCount = GUICtrlCreateInput("N/A",154,480,596,20,$ES_READONLY)
GUISetState()

_LoadTree(GUICtrlRead($DirInput), $MainTree,0)


While 1;Main Loop
    $Msg = GUIGetMsg()
Select
    Case $Msg = $GUI_EVENT_CLOSE
        Exit

    Case $msg = $BrowseBtn 
        GUICtrlDelete($MainTree)
        $MainTree = GUICtrlCreateTreeView(1, 60, 250, 417)
        GUICtrlSetImage(-1,"shell32.dll",3,4)
        GUICtrlSetImage(-1,"shell32.dll",4,2)
        GUICtrlSetdata($CurrentPath,GUICtrlRead($DirInput))
        _LoadTree(GUICtrlRead($DirInput), $MainTree,0);Path/Tree/State
        
            
    Case $msg > 4
        _GUICtrlListViewDeleteAllItems($SubTree)
        $Read = GUICtrlread($MainTree,1)
        GUICtrlSetdata($CurrentPath,GUICtrlRead($DirInput) & $Read[0] & "\")
        _LoadTree(GUICtrlRead($DirInput) & $Read[0] & "\", $SubTree,1);Path/Tree/State
        GUICtrlSetdata($ObjCount,_GUICtrlListViewGetItemCount($SubTree) & " Object(s)")
        $TheSize = DirGetSize(GUICtrlRead($Currentpath)) / 1024 / 1024
        $FreeSpace = DriveSpaceFree(Stringleft(GUICtrlRead($DirInput),3))/ 1024
        GUICtrlSetdata($SpaceCount,Stringleft($TheSize,Stringinstr($TheSize,".")+2) & " MB (Free Space: "& StringLeft($FreeSpace,StringInStr($FreeSpace,".")+1) & " GB)")

EndSelect
Wend;Mainloop end

;                Functions
;////////////////////////////////////////////
Func _LoadTree($sRoot, $hParent, $GetFiles)
    Local $ThePath = GUICtrlRead($CurrentPath)
    Local $sMask = "*.*"
    Local $aFile[1], $nCnt = 1, $newParent
    Local $hSearch = FileFindFirstFile($sRoot & $sMask)
    If $hSearch >= 0 Then
       $sFile = FileFindNextFile($hSearch)
       While not @error
            ReDim $aFile[$nCnt]
            $aFile[$nCnt-1] = $sFile
            $nCnt = $nCnt + 1
            $sFile = FileFindNextFile($hSearch)
       Wend
       FileClose($hSearch)
    EndIf
    For $i = 0 To UBound($aFile) - 1
        If $aFile[$i] == "." or $aFile[$i] == ".." Then ContinueLoop
        If $GetFiles = 0 Then;Do not include files
            If StringInStr(FileGetAttrib($sRoot & "\" & $aFile[$i]), "D") Then
                $newParent = GUICtrlCreateTreeViewItem($aFile[$i], $hParent)
                _LoadTree($sRoot & $aFile[$i] & "\", $newParent,0);Keep search trough folders
                ContinueLoop
            Endif
        ElseIf $GetFiles = 1 Then;Include Files
            $FilegetSize = Round(FileGetSize($ThePath & $aFile[$i]) / 1024,0) 
            $Time = FileGetTime($ThePath & $aFile[$i], 1)
            If Not @Error Then
                $yyyymd = $Time[2] & "." & $Time[1] & "." & $Time[0] & " " & $Time[3] & ":" & $Time[4]
                If StringInStr(FileGetAttrib($sRoot & "\" & $aFile[$i]), "D") Then
                    $SnewParent = GUICtrlCreateListViewItem($aFile[$i] &"||"& _FileGetType($ThePath & $aFile[$i]) &"|"& $yyyymd, $hParent)
                    ContinueLoop
                Endif
                GUICtrlCreateListViewItem($aFile[$i] &"|"& $FilegetSize & " KB" &"|"& _FileGetType($ThePath & $aFile[$i]) &"|"& $yyyymd, $hParent);Include files
            EndIf
        EndIf
    Next
EndFunc


Func _FileGetExt($sFileName)
    Dim $DotPos, $Other
    $DotPos = StringInStr($sFileName, '.', 1, -1)
    If $DotPos = 0 Then Return ''
    $Other = StringInStr($sFileName, '\', 1, -1)
    If $Other > $DotPos Then Return ''
    $Other = StringInStr($sFileName, ':', 1, -1)
    If $Other > $DotPos Then Return ''
    Return StringTrimLeft($sFileName, $DotPos)
EndFunc
Func _FileGetType($sFileName)
    Dim $Type
    If StringInStr(FileGetAttrib($sFileName),"D") Then
        $Type = RegRead('HKEY_CLASSES_ROOT\Folder', '')
    Else
        Dim $Ext = _FileGetExt($sFileName)
        $Type = RegRead('HKEY_CLASSES_ROOT\.' & $Ext, '')
        If $Type = '' Then
            $Type = $Ext & '-file'
        Else
            Dim $Type2 = RegRead('HKEY_CLASSES_ROOT\' & $Type, '')
            If $Type2 <> '' Then $Type = $Type2
        EndIf
    EndIf
    Return $Type
EndFunc
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...