Jump to content

Get listview for array of directories


Recommended Posts

I'm think my code isnt simple as much but can anyone help me do something like this:

From Array:

D:\Parents\Child\Text 1.txt

to List view

Parents | Child | Text 1

and if I click Text, It will return Full Dir of that file?

This is my code:

#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIListView.au3>

;Search File if exits


$aData = _FileListToArrayEx("D:\ParrentDir", '*.txt',1)
$bData = _FileListToArrayEx("D:\ParrentDir", '*.txt',1)
$cData = _FileListToArrayEx("D:\ParrentDir", '*.txt',1)
For $i = 1 To $aData[0]
; Link demo : D:\ParentDir\Child\text file.txt
$aData[$i] = StringRegExpReplace($aData[$i],"D:\\ParrentDir\\","")
$aData[$i] = StringRegExpReplace($aData[$i],"\\(.*)","")
$bData[$i] = StringRegExpReplace($bData[$i],"D:\\ParentDir\\(.*)\\(.*)","\1")
$cData[$i] = StringRegExpReplace($cData[$i],"D:\\ParentDir\\(.*)\\","")
$cData[$i] = StringRegExpReplace($cData[$i],".txt,"")
Next

$iw = 600
$ih = 500
$hGUI = GUICreate("Test", $iw, $ih)
$cListView = GUICtrlCreateListView("", 10, 10, $iw-20, $ih-20)
_GUICtrlListView_AddColumn($cListView, "Parrent", 150)
_GUICtrlListView_AddColumn($cListView, "Child", 200)
_GUICtrlListView_AddColumn($cListView, "Files", 100)
GUISetState()

For $i = 1 To $aData[0]
$iItem = _GUICtrlListView_AddItem($cListView, $aData[$i])
_GUICtrlListView_AddSubItem($cListView, $iItem, $bData[$i], 1)
_GUICtrlListView_AddSubItem($cListView, $iItem, $cData[$i], 2)
Next

While 1
Switch GUIGetMsg()
     Case $GUI_EVENT_CLOSE
         Exit
EndSwitch
WEnd

;===============================================================================
;
; Description: lists all or preferred files and or folders in a specified path (Similar to using Dir with the /B Switch)
; Syntax:        _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $sExclude = '')
; Parameter(s):  $sPath = Path to generate filelist for
;                $sFilter = The filter to use. Search the Autoit3 manual for the word "WildCards" For details, support now for multiple searches
;                        Example *.exe; *.txt will find all .exe and .txt files
;                $iFlag = determines weather to return file or folders or both.
;                $sExclude = exclude a file from the list by all or part of its name
;                        Example: Unins* will remove all files/folders that start with Unins
;                    $iFlag=0(Default) Return both files and folders
;                    $iFlag=1 Return files Only
;                    $iFlag=2 Return Folders Only
;
; Requirement(s): None
; Return Value(s): On Success - Returns an array containing the list of files and folders in the specified path
;                    On Failure - Returns the an empty string "" if no files are found and sets @Error on errors
;                    @Error or @extended = 1 Path not found or invalid
;                    @Error or @extended = 2 Invalid $sFilter or Invalid $sExclude
;                    @Error or @extended = 3 Invalid $iFlag
;                    @Error or @extended = 4 No File(s) Found
;
; Author(s):     SmOke_N
; Note(s):       The array returned is one-dimensional and is made up as follows:
;                $array[0] = Number of Files\Folders returned
;                $array[1] = 1st File\Folder
;                $array[2] = 2nd File\Folder
;                $array[3] = 3rd File\Folder
;                $array[n] = nth File\Folder
;
;                All files are written to a "reserved" .tmp file (Thanks to gafrost) for the example
;                The Reserved file is then read into an array, then deleted
;===============================================================================

Func _FileListToArrayEx($s_path, $s_mask = "*.*", $i_flag = 0, $s_exclude = -1, $f_recurse = True, $f_full_path = True)
If FileExists($s_path) = 0 Then Return SetError(1, 1, 0)
; Strip trailing backslash, and add one after to make sure there's only one
$s_path = StringRegExpReplace($s_path, "[\\/]+\z", "") & "\"
; Set all defaults
If $s_mask = -1 Or $s_mask = Default Then $s_mask = "*.*"
If $i_flag = -1 Or $i_flag = Default Then $i_flag = 0
If $s_exclude = -1 Or $s_exclude = Default Then $s_exclude = ""
; Look for bad chars
If StringRegExp($s_mask, "[/:><\|]") Or StringRegExp($s_exclude, "[/:><\|]") Then
     Return SetError(2, 2, 0)
EndIf
; Strip leading spaces between semi colon delimiter
$s_mask = StringRegExpReplace($s_mask, "\s*;\s*", ";")
If $s_exclude Then $s_exclude = StringRegExpReplace($s_exclude, "\s*;\s*", ";")
; Confirm mask has something in it
If StringStripWS($s_mask, 8) = "" Then Return SetError(2, 2, 0)
If $i_flag < 0 Or $i_flag > 2 Then Return SetError(3, 3, 0)
; Validate and create path + mask params
Local $a_split = StringSplit($s_mask, ";"), $s_hold_split = ""
For $i = 1 To $a_split[0]
     If StringStripWS($a_split[$i], 8) = "" Then ContinueLoop
     If StringRegExp($a_split[$i], "^\..*?\..*?\z") Then
         $a_split[$i] &= "*" & $a_split[$i]
     EndIf
     $s_hold_split &= '"' & $s_path & $a_split[$i] & '" '
Next
$s_hold_split = StringTrimRight($s_hold_split, 1)
If $s_hold_split = "" Then $s_hold_split = '"' & $s_path & '*.*"'
Local $i_pid, $s_stdout, $s_hold_out, $s_dir_file_only = "", $s_recurse = "/s "
If $i_flag = 1 Then $s_dir_file_only = ":-d"
If $i_flag = 2 Then $s_dir_file_only = ":D"
If Not $f_recurse Then $s_recurse = ""
$i_pid = Run(@ComSpec & " /c dir /b " & $s_recurse & "/a" & $s_dir_file_only & " " & $s_hold_split, "", @SW_HIDE, 4 + 2)
While 1
     $s_stdout = StdoutRead($i_pid)
     If @error Then ExitLoop
     $s_hold_out &= $s_stdout
WEnd
$s_hold_out = StringRegExpReplace($s_hold_out, "\v+\z", "")
If Not $s_hold_out Then Return SetError(4, 4, 0)
; Parse data and find matches based on flags
Local $a_fsplit = StringSplit(StringStripCR($s_hold_out), @LF), $s_hold_ret
$s_hold_out = ""
If $s_exclude Then $s_exclude = StringReplace(StringReplace($s_exclude, "*", ".*?"), ";", "|")
For $i = 1 To $a_fsplit[0]
     If $s_exclude And StringRegExp(StringRegExpReplace( _
         $a_fsplit[$i], "(.*?[\\/]+)*(.*?\z)", "\2"), "(?i)\Q" & $s_exclude & "\E") Then ContinueLoop
     If StringRegExp($a_fsplit[$i], "^\w:[\\/]+") = 0 Then $a_fsplit[$i] = $s_path & $a_fsplit[$i]
     If $f_full_path Then
         $s_hold_ret &= $a_fsplit[$i] & Chr(1)
     Else
         $s_hold_ret &= StringRegExpReplace($a_fsplit[$i], "((?:.*?[\\/]+)*)(.*?\z)", "$2") & Chr(1)
     EndIf
Next
$s_hold_ret = StringTrimRight($s_hold_ret, 1)
If $s_hold_ret = "" Then Return SetError(5, 5, 0)
Return StringSplit($s_hold_ret, Chr(1))
EndFunc
$Money = ControlGetMoney(@Life,"People","Pocket4")If $Money Then $Rich = TrueElse $Risk = True _RunAwayFromPolice("Fastest")EndIf
Link to comment
Share on other sites

  • Moderators

DucViet,

I have used my own UDF to get the file list (I understand how it works) and this script should do what you want. Note that you need to double-click on the file name to get a return - ListViews tend to eat single-clicks as "item selection" clicks and I do not recommend using them as triggers: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <GUIListView.au3>

#include <RecFileListToArray.au3>

Global $sParentDir = "D:\ParrentDir"
Global $sFileMask = "*.txt"

; Get sorted list of files
$aList = _RecFileListToArray($sParentDir, $sFileMask, 1, 1, 1, 1)

$iw = 600
$ih = 500
$hGUI = GUICreate("Test", $iw, $ih)
$cListView = GUICtrlCreateListView("", 10, 10, $iw - 20, $ih - 20)
_GUICtrlListView_AddColumn($cListView, "Parent", 186)
_GUICtrlListView_AddColumn($cListView, "Child", 186)
_GUICtrlListView_AddColumn($cListView, "File", 186)

; Loop through file list
For $i = 1 To $aList[0]
    ; Start item creation with parent
    $sItem = $sParentDir & "|"
    ; If there are "\" then extract child folder section - if not then leave empty
    If StringInStr($aList[$i], "\") Then
        $sItem &= StringRegExpReplace($aList[$i], "(^.*)\\(.*)", "\1") & "|"
    Else
        $sItem &= "|"
    EndIf
    ; Add filename stripped of extension
    $sItem &= StringRegExpReplace($aList[$i], "^.*\\|\..*$", "")
    ; Create item
    GUICtrlCreateListViewItem($sItem, $cListView)
Next

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd


Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    ; Struct = $tagNMHDR and "int Item;int SubItem" from $tagNMLISTVIEW
    Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam)
    If @error Then Return

    ; Ckeck it was a double-click
    If BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF) = -3 Then ; $NM_DBLCLK
        ; Check it was on filename (3rd column)
        If DllStructGetData($tStruct, 5) = 2 Then
            ; Get row value
            $iRow = DllStructGetData($tStruct, 4)
            ; Reconstruct the full path from the array
            MsgBox(0, "Full Path", $sParentDir & "\" & $aList[$iRow + 1])
        EndIf
    EndIf

EndFunc

All clear? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Clearly~ except your UDF, that code is so terriable and .... I need to create a button to do the same thing like dbclick.

So confuse....

Anyway, tks for your help

Edited by DucViet
$Money = ControlGetMoney(@Life,"People","Pocket4")If $Money Then $Rich = TrueElse $Risk = True _RunAwayFromPolice("Fastest")EndIf
Link to comment
Share on other sites

  • Moderators

DucViet,

Why do you say these 2 lines from my script:

#include <RecFileListToArray.au3>

$aList = _RecFileListToArray($sParentDir, $sFileMask, 1, 1, 1, 1)

are "terriable" when compared to what you had originally?

[autoit]
$aData = _FileListToArrayEx("D:\ParrentDir", '*.txt',1)

;
; Description: lists all or preferred files and or folders in a specified path (Similar to using Dir with the /B Switch)
; Syntax:        _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $sExclude = '')
; Parameter(s):  $sPath = Path to generate filelist for
;                $sFilter = The filter to use. Search the Autoit3 manual for the word "WildCards" For details, support now for multiple searches
;                        Example *.exe; *.txt will find all .exe and .txt files
;                $iFlag = determines weather to return file or folders or both.
;                $sExclude = exclude a file from the list by all or part of its name
;                        Example: Unins* will remove all files/folders that start with Unins
;                    $iFlag=0(Default) Return both files and folders
;                    $iFlag=1 Return files Only
;                    $iFlag=2 Return Folders Only
;
; Requirement(s): None
; Return Value(s): On Success - Returns an array containing the list of files and folders in the specified path
;                    On Failure - Returns the an empty string "" if no files are found and sets @Error on errors
;                    @Error or @extended = 1 Path not found or invalid
;                    @Error or @extended = 2 Invalid $sFilter or Invalid $sExclude
;                    @Error or @extended = 3 Invalid $iFlag
;                    @Error or @extended = 4 No File(s) Found
;
; Author(s):     SmOke_N
; Note(s):       The array returned is one-dimensional and is made up as follows:
;                $array[0] = Number of Files\Folders returned
;                $array[1] = 1st File\Folder
;                $array[2] = 2nd File\Folder
;                $array[3] = 3rd File\Folder
;                $array[n] = nth File\Folder
;
;                All files are written to a "reserved" .tmp file (Thanks to gafrost) for the example
;                The Reserved file is then read into an array, then deleted
;===============================================================================

Func _FileListToArrayEx($s_path, $s_mask = "*.*", $i_flag = 0, $s_exclude = -1, $f_recurse = True, $f_full_path = True)
If FileExists($s_path) = 0 Then Return SetError(1, 1, 0)
; Strip trailing backslash, and add one after to make sure there's only one
$s_path = StringRegExpReplace($s_path, "[\\/]+\z", "") & "\"
; Set all defaults
If $s_mask = -1 Or $s_mask = Default Then $s_mask = "*.*"
If $i_flag = -1 Or $i_flag = Default Then $i_flag = 0
If $s_exclude = -1 Or $s_exclude = Default Then $s_exclude = ""
; Look for bad chars
If StringRegExp($s_mask, "[/:><\|]") Or StringRegExp($s_exclude, "[/:><\|]") Then
     Return SetError(2, 2, 0)
EndIf
; Strip leading spaces between semi colon delimiter
$s_mask = StringRegExpReplace($s_mask, "\s*;\s*", ";")
If $s_exclude Then $s_exclude = StringRegExpReplace($s_exclude, "\s*;\s*", ";")
; Confirm mask has something in it
If StringStripWS($s_mask, 8) = "" Then Return SetError(2, 2, 0)
If $i_flag < 0 Or $i_flag > 2 Then Return SetError(3, 3, 0)
; Validate and create path + mask params
Local $a_split = StringSplit($s_mask, ";"), $s_hold_split = ""
For $i = 1 To $a_split[0]
     If StringStripWS($a_split[$i], 8) = "" Then ContinueLoop
     If StringRegExp($a_split[$i], "^\..*?\..*?\z") Then
         $a_split[$i] &= "*" & $a_split[$i]
     EndIf
     $s_hold_split &= '"' & $s_path & $a_split[$i] & '" '
Next
$s_hold_split = StringTrimRight($s_hold_split, 1)
If $s_hold_split = "" Then $s_hold_split = '"' & $s_path & '*.*"'
Local $i_pid, $s_stdout, $s_hold_out, $s_dir_file_only = "", $s_recurse = "/s "
If $i_flag = 1 Then $s_dir_file_only = ":-d"
If $i_flag = 2 Then $s_dir_file_only = ":D"
If Not $f_recurse Then $s_recurse = ""
$i_pid = Run(@ComSpec & " /c dir /b " & $s_recurse & "/a" & $s_dir_file_only & " " & $s_hold_split, "", @SW_HIDE, 4 + 2)
While 1
     $s_stdout = StdoutRead($i_pid)
     If @error Then ExitLoop
     $s_hold_out &= $s_stdout
WEnd
$s_hold_out = StringRegExpReplace($s_hold_out, "\v+\z", "")
If Not $s_hold_out Then Return SetError(4, 4, 0)
; Parse data and find matches based on flags
Local $a_fsplit = StringSplit(StringStripCR($s_hold_out), @LF), $s_hold_ret
$s_hold_out = ""
If $s_exclude Then $s_exclude = StringReplace(StringReplace($s_exclude, "*", ".*?"), ";", "|")
For $i = 1 To $a_fsplit[0]
     If $s_exclude And StringRegExp(StringRegExpReplace( _
         $a_fsplit[$i], "(.*?[\\/]+)*(.*?\z)", "\2"), "(?i)\Q" & $s_exclude & "\E") Then ContinueLoop
     If StringRegExp($a_fsplit[$i], "^\w:[\\/]+") = 0 Then $a_fsplit[$i] = $s_path & $a_fsplit[$i]
     If $f_full_path Then
         $s_hold_ret &= $a_fsplit[$i] & Chr(1)
     Else
         $s_hold_ret &= StringRegExpReplace($a_fsplit[$i], "((?:.*?[\\/]+)*)(.*?\z)", "$2") & Chr(1)
     EndIf
Next
$s_hold_ret = StringTrimRight($s_hold_ret, 1)
If $s_hold_ret = "" Then Return SetError(5, 5, 0)
Return StringSplit($s_hold_ret, Chr(1))
EndFunc

You do understand how to use #include files, I hope? If not then please ask as they are a fundamental part of AutoIt coding - by using them you can benefit from complicated code (like my UDF) in your scripts very simply indeed. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

M23,

Sorry I didnt mean that, what I meant is its hard for me,newbie, to understand what exacly it does.

And yes, I do understand #include, but I dont know how to get a return by clicking a button

Sorry for misunderstanding, I'm bad in English...

$Money = ControlGetMoney(@Life,"People","Pocket4")If $Money Then $Rich = TrueElse $Risk = True _RunAwayFromPolice("Fastest")EndIf
Link to comment
Share on other sites

  • Moderators

DucViet,

No problems - I just wanted to be sure you understood about #includes. And the UDF is not that complicated - even though it might look it at first. :D

Here is a version of the script with a button: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <GUIListView.au3>

#include <RecFileListToArray.au3>

Global $sParentDir = "D:\ParrentDir"
Global $sFileMask = "*.txt"

; Get sorted list of files
$aList = _RecFileListToArray($sParentDir, $sFileMask, 1, 1, 1, 1)

$iw = 600
$ih = 500
$hGUI = GUICreate("Test", $iw, $ih)

$cButton = GUICtrlCreateButton("Full Path", ($iw / 2) - 40, $ih - 40, 80 , 30)

$cListView = GUICtrlCreateListView("", 10, 10, $iw - 20, $ih - 60)
_GUICtrlListView_AddColumn($cListView, "Parent", 186)
_GUICtrlListView_AddColumn($cListView, "Child", 186)
_GUICtrlListView_AddColumn($cListView, "File", 186)

; Loop through file list
For $i = 1 To $aList[0]
    ; Start item creation with parent
    $sItem = $sParentDir & "|"
    ; If there are "\" then extract child folder section - if not then leave empty
    If StringInStr($aList[$i], "\") Then
        $sItem &= StringRegExpReplace($aList[$i], "(^.*)\\(.*)", "\1") & "|"
    Else
        $sItem &= "|"
    EndIf
    ; Add filename stripped of extension
    $sItem &= StringRegExpReplace($aList[$i], "^.*\\|\..*$", "")
    ; Create item
    GUICtrlCreateListViewItem($sItem, $cListView)
Next

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton
            $iItem = _GUICtrlListView_GetSelectedIndices($cListView)
            ; Reconstruct the full path from the array
            MsgBox(0, "Full Path", $sParentDir & "\" & $aList[$iItem + 1])

    EndSwitch
WEnd


Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    ; Struct = $tagNMHDR and "int Item;int SubItem" from $tagNMLISTVIEW
    Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam)
    If @error Then Return

    ; Ckeck it was a double-click
    If BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF) = -3 Then ; $NM_DBLCLK
        ; Check it was on filename (3rd column)
        If DllStructGetData($tStruct, 5) = 2 Then
            ; Get row value
            $iRow = DllStructGetData($tStruct, 4)
            ; Reconstruct the full path from the array
            MsgBox(0, "Full Path", $sParentDir & "\" & $aList[$iRow + 1])
        EndIf
    EndIf

EndFunc

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

M23,

Actually I wanna to take a "Child1" to be Parent and Child2 to be Child :(

I tried to change source but nothing happened.

I changed the code

; Loop through file list
For $i = 1 To $aList[0]
    ; Removing driver letter
$reParentDir = StringRegExpReplace($sParentDir,"(.*)\:\\","")
    ; Start item creation with parent
    ;$sParentList = $aList[$i] & "|" ; $sItem = $reParentDir & "|"
$sItem = StringRegExpReplace($aList[$i], "(^.*)\\(.*)", "\1") & "|"
    ; If there are "\" then extract child folder section - if not then leave empty
    If StringInStr($aList[$i], "\") Then
  $sItem = StringReplace($aList[$i], "\","|",2)
 ;$sItem = StringRegExpReplace($aList[$i], "(^.*)\\(.*)", "\1") & "|"
    Else
        $sItem &= "|"
    EndIf
    ; Add filename stripped of extension
    $sItem &= StringRegExpReplace($aList[$i], "^.*\\|\..*$", "")
    ; Create item
    GUICtrlCreateListViewItem($sItem, $cListView)
Next

and the output is like this:

Child1 | Child2 | Child3File.txt

If it doesnt have child2 then

Child1 | File.txt

But I want it should be:

Child1 | Child2Child3 | File.txt

Or

Child1 | Child2 | *Child3* | File.txt

Will be ok :) Edited by DucViet
$Money = ControlGetMoney(@Life,"People","Pocket4")If $Money Then $Rich = TrueElse $Risk = True _RunAwayFromPolice("Fastest")EndIf
Link to comment
Share on other sites

  • Moderators

DucViet,

Something like this perhaps: :)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <GUIListView.au3>

#include <RecFileListToArray.au3>

Global $sParentDir = "D:\ParrentDir"
Global $sFileMask = "*.txt"

$iw = 600
$ih = 500

; Get sorted list of files
$aList = _RecFileListToArray($sParentDir, $sFileMask, 1, 1, 1, 1)
If @Error Then
    MsgBox(0, "Error", "No files found")
    Exit
EndIf

; Loop through list to see how many columns we need
$iMaxCols = 0
For $i = 1 to $aList[0]
    StringReplace($aList[$i], "\", "\", 0, 2)
    $iSlashes = @extended
    If $iSlashes > $iMaxCols Then
        $iMaxCols = $iSlashes
    EndIf
Next
; Calsulate size of child columns
$iColSize = Floor(($iw - 40) / ($iMaxCols + 1)) - 10
ConsoleWrite($iColSize & @CRLF)

; Create GUUI
$hGUI = GUICreate($sParentDir, $iw, $ih)

$cButton = GUICtrlCreateButton("Full Path", ($iw / 2) - 40, $ih - 40, 80 , 30)

$cListView = GUICtrlCreateListView("", 10, 10, $iw - 20, $ih - 60)
For $i = 1 To $iMaxCols
    _GUICtrlListView_AddColumn($cListView, "Child " & $i, $iColSize)
Next
_GUICtrlListView_AddColumn($cListView, "File", $iColSize + ($iMaxCols * 10))

; Loop through file list
For $i = 1 To $aList[0]
    ; Split path on "\"
    $aSplit = StringSplit($aList[$i], "\")
    ; Item creation
    $sItem = ""
    ; Add the existing children
    For $j = 1 To $aSplit[0] - 1
        $sItem &= $aSplit[$j] & "|"
    Next
    ; Fill in the blanks
    For $k = $j To $iMaxCols
        $sItem &= "|"
    Next
    ; Add the file name
    $sItem &= $aSplit[$aSplit[0]]
    ; Create item
    GUICtrlCreateListViewItem($sItem, $cListView)
Next

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton
            $iItem = _GUICtrlListView_GetSelectedIndices($cListView)
            ; Reconstruct the full path from the array
            MsgBox(0, "Full Path", $sParentDir & "\" & $aList[$iItem + 1])
    EndSwitch
WEnd

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    ; Struct = $tagNMHDR and "int Item;int SubItem" from $tagNMLISTVIEW
    Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam)
    If @error Then Return

    ; Ckeck it was a double-click
    If BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF) = -3 Then ; $NM_DBLCLK
        ; Check it was on filename (last column)
        If DllStructGetData($tStruct, 5) = $iMaxCols Then
            ; Get row value
            $iRow = DllStructGetData($tStruct, 4)
            ; Reconstruct the full path from the array
            MsgBox(0, "Full Path", $sParentDir & "\" & $aList[$iRow + 1])
        EndIf
    EndIf

EndFunc

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

M23,

Ok, Its work, but can you explain this code?

$iMaxCols = 0
For $i = 1 to $aList[0]
    StringReplace($aList[$i], "\", "\", 0, 2)
    $iSlashes = @extended
    If $iSlashes > $iMaxCols Then
        $iMaxCols = $iSlashes
    EndIf
Next

Why do you write this?

StringReplace($aList[$i], "", "", 0, 2)

And about RecFileListToArray, can I read list files and sort it into "Last modified time" ?

Because I'm wanna create an update function to download from server, and highlight new files :D

$Money = ControlGetMoney(@Life,"People","Pocket4")If $Money Then $Rich = TrueElse $Risk = True _RunAwayFromPolice("Fastest")EndIf
Link to comment
Share on other sites

  • Moderators

DucViet,

The code works like this:

; Declare a veriable to hold the number of columns we will need to show the longest path
$iMaxCols = 0 ; Set it to 0 initially
; Now loop through the list of paths
For $i = 1 to $aList[0]
    ; And see how many "\" there are in each one - this will tell us the number of separate folders in the path and so haow many columns we need
    ; We use StringReplace but do not assign the return so that the actual path is unchanged
    ; The parameters are as described in the Help file: ( 0 = replace all; 2 = use fast algorithm )
    StringReplace($aList[$i], "\", "\", 0, 2)
    ; The number of replacements made is returned in @extended - also explained in the Help file
    $iSlashes = @extended
    ; So we see if we have more than the current number of columns needed
    If $iSlashes > $iMaxCols Then
        ; And replace it if we do
        $iMaxCols = $iSlashes
    EndIf
Next

All clear? :)

The UDF will not list the files and then sort by "Last Modified Time" directly. You will need to get a list with the UDF and then get the time value for each file. I showed how to do it for file size here - it shoullnot be too hard to adapt to use the time value instead. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

DucViet,

My pleasure as always. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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