Jump to content
Sign in to follow this  
ZeR0

List files of dir to Listview

Recommended Posts

ZeR0

Happy New Year!!!

I have problems with simple code, i making 1 file manager, but i have problems...

I need List al files of a dir to 1 List view, i not want use _ArrayDisplay because i need in 1 array made by me..

Tanks and happy new year

Share this post


Link to post
Share on other sites
ZeR0

Look at

_FileListToArray()

GUICtrlCreateListViewItem()

In helpfile there are also nice examples for that.

Tanks, i have that:

#Include <File.au3>
#Include <Array.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)


#Region ### START Koda GUI section ### Form=Form1.kxf
$Form1 = GUICreate("[X]RT - File Manager -[Localhost/Administrador]-", 717, 394, 190, 108)
$Combo1 = GUICtrlCreateCombo("Drivers", 8, 8, 249, 25)
$Button1 = GUICtrlCreateButton("Get Drivers", 264, 8, 185, 25, $BS_DEFPUSHBUTTON)
GUICtrlSetOnEvent(-1, "Main")
GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")
$ListView1 = GUICtrlCreateListView("Row", 64, 96, 353, 129)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 90)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
    Case $GUI_EVENT_CLOSE
Exit


Func Main()
$var = DriveGetDrive( "all" )
If NOT @error Then
    For $i = 1 to $var[0]
    $sys = "" & $var[1] & ""
    GUICtrlSetData($Combo1, "" & $var[$i] & "")
    Next

EndIf
$FileList=_FileListToArray(@DesktopDir)
If @Error=1 Then
    MsgBox (0,"","No Files\Folders Found.")
    Exit
EndIf
$ListView1_0 = GUICtrlCreateListViewItem("" & $FileList & "", $ListView1)
EndFunc

        
EndSwitch
WEnd

Share this post


Link to post
Share on other sites
Andreik

Tanks, i have that:

#Include <File.au3>
#Include <Array.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)


#Region ### START Koda GUI section ### Form=Form1.kxf
$Form1 = GUICreate("[X]RT - File Manager -[Localhost/Administrador]-", 717, 394, 190, 108)
$Combo1 = GUICtrlCreateCombo("Drivers", 8, 8, 249, 25)
$Button1 = GUICtrlCreateButton("Get Drivers", 264, 8, 185, 25, $BS_DEFPUSHBUTTON)
GUICtrlSetOnEvent(-1, "Main")
GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")
$ListView1 = GUICtrlCreateListView("Row", 64, 96, 353, 129)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 90)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
    Case $GUI_EVENT_CLOSE
Exit


Func Main()
$var = DriveGetDrive( "all" )
If NOT @error Then
    For $i = 1 to $var[0]
    $sys = "" & $var[1] & ""
    GUICtrlSetData($Combo1, "" & $var[$i] & "")
    Next

EndIf
$FileList=_FileListToArray(@DesktopDir)
If @Error=1 Then
    MsgBox (0,"","No Files\Folders Found.")
    Exit
EndIf
$ListView1_0 = GUICtrlCreateListViewItem("" & $FileList & "", $ListView1)
EndFunc

        
EndSwitch
WEnd
Your code is wrong. Look an example of files list:

#include <File.au3>
$DIR = FileSelectFolder("SELECT FOLDER","")
$FILE = _FileListToArray($DIR,"*",1)
$GUI = GUICreate("Example",400,400)
$LISTVIEW = GUICtrlCreateListView("File name|Extension",5,5,390,390,BitOR(0x00100000,0x00200000))
For $INDEX = 1 To $FILE[0]
    $POINT = StringInStr($FILE[$INDEX],".",0,-1)
    If $POINT <> 0 Then
        GUICtrlCreateListViewItem(StringLeft($FILE[$INDEX],$POINT-1) & "|" & StringRight($FILE[$INDEX],StringLen($FILE[$INDEX])-$POINT),$LISTVIEW)
    EndIf
Next
GUISetState()

While 1
    $MSG = GUIGetMsg()
    If $MSG = -3 Then Exit
    Sleep(20)
WEnd

When the words fail... music speaks

Share this post


Link to post
Share on other sites
ZeR0

Your code is wrong. Look an example of files list:

#include <File.au3>
$DIR = FileSelectFolder("SELECT FOLDER","")
$FILE = _FileListToArray($DIR,"*",1)
$GUI = GUICreate("Example",400,400)
$LISTVIEW = GUICtrlCreateListView("File name|Extension",5,5,390,390,BitOR(0x00100000,0x00200000))
For $INDEX = 1 To $FILE[0]
    $POINT = StringInStr($FILE[$INDEX],".",0,-1)
    If $POINT <> 0 Then
        GUICtrlCreateListViewItem(StringLeft($FILE[$INDEX],$POINT-1) & "|" & StringRight($FILE[$INDEX],StringLen($FILE[$INDEX])-$POINT),$LISTVIEW)
    EndIf
Next
GUISetState()

While 1
    $MSG = GUIGetMsg()
    If $MSG = -3 Then Exit
    Sleep(20)
WEnd

Tanks :DDD

Share this post


Link to post
Share on other sites
GreenCan

Hi ZeRo

This function works:

GreenCan

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <File.au3>


Content(FileSelectFolder("SELECT FOLDER",""))
Exit

Func Content($directory)
    Local $listview, $button, $item1, $item2, $item3, $input1, $msg
    
    ; _FileListToArray
    $FileList=_FileListToArray($directory,'*.*',  1) ; Only files
    If @Error=1 Then
        MsgBox (0,"","No Files\Folders Found.")
    EndIf   

    GUICreate("Directory " & $directory, 800, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
    GUISetBkColor(0x00E0FFFF)  ; will change background color

    $listview = GUICtrlCreateListView("File Name                                               |Size              |creation Time (YYYY/MM/DD HH:MM:SS             ", 10, 10, 780, 190);,$LVS_SORTDESCENDING)
    for $n = 1 to UBound($FileList)-1
        $File_Name = $FileList[$n]
        $File_size = FileGetSize ( $directory & "\" & $File_Name)
        $File_t =  FileGetTime($directory & "\" & $File_Name, 1) ; creation Time
        $File_time = $File_t[0] & "/" & $File_t[1] & "/" & $File_t[2] & " " & $File_t[3] & ":" & $File_t[4] & ":" & $File_t[5] ; detailed
        $item = GUICtrlCreateListViewItem( $File_Name & "|" & $File_size & "|" & $File_time, $listview)
    Next
    GUISetState()

    Do
        $msg = GUIGetMsg()
    Until $msg = $GUI_EVENT_CLOSE
EndFunc   ;==>Content

Contributions

CheckUpdate - SelfUpdating script ------- Self updating script

Dynamic input validation ------------------- Use a Input masks can make your life easier and Validation can be as simple

MsgBox with CountDown ------------------- MsgBox with visual countdown

Display Multiline text cells in ListView ---- Example of pop-up or ToolTip for multiline text items in ListView

Presentation Manager ---------------------- Program to display and refresh different Border-less GUI's on a Display (large screen TV)

USB Drive Tools ------------------------------ Tool to help you with your USB drive management

Input Period udf ------------------------------ GUI for a period input

Excel ColorPicker ---------------------------- Color pickup tool will allow you to select a color from the standard Excel color palette

Excel Chart UDF ----------------------------- Collaboration project with water 

GetDateInString ------------------------------ Find date/time in a string using a date format notation like DD Mon YYYY hh:mm

TaskListAllDetailed --------------------------- List All Scheduled Tasks

Computer Info --------------------------------- A collection of information for helpdesk

Shared memory Demo ----------------------- Demo: Two applications communicate with each other through means of a memory share (using Nomad function, 32bit only)

Universal Date Format Conversion -------- Universal date converter from your PC local date format to any format

Disable Windows DetailsPane -------------- Disable Windows Explorer Details Pane

Oracle SQL Report Generator -------------  Oracle Report generator using SQL

SQLite Report Generator -------------------  SQLite Report generator using SQL

SQLite ListView and BLOB demo ---------- Demo: shows how binary (image) objects can be recognized natively in a database BLOB field

DSN-Less Database connection demo --- Demo: ActiveX Data Objects DSN-Less Database access

Animated animals ----------------------------- Fun: Moving animated objects

Perforated image in GUI --------------------- Fun: Perforate your image with image objects

UEZ's Perforator major update ------------- Fun: Pro version of Perforator by UEZ

Visual Crop Tool (GUI) ----------------------- Easy to use Visual Image Crop tool

Visual Image effect (GUI) -------------------- Visually apply effects on an image

 

 

 

Share this post


Link to post
Share on other sites
ZeR0

Hi GreenCan Tank u!

But i need sonthing more, i need list files and directories, the function only list files and the

the help file does not say anything about it :SSS

Share this post


Link to post
Share on other sites
GreenCan

Hi GreenCan Tank u!

But i need sonthing more, i need list files and directories, the function only list files and the

the help file does not say anything about it :SSS

Hi ZeRo,

I have two methods:

Method 1 is the most simple, just ask for files and folders. Problem, the sort will mix files and folders. I also added Icons to the listview:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <File.au3>

Content(FileSelectFolder("SELECT FOLDER",""))
Exit

Func Content($directory)
    Local $FileList, $item, $File_Name, $File_size, $File_t, $File_time
    
    ; _FileListToArray
    $FileList=_FileListToArray($directory,'*.*',  0) ; files and directories
    If @Error=1 Then
        MsgBox (0,"","No Files Found.")
    EndIf   

    GUICreate("Directory " & $directory, 800, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
    GUISetBkColor(0x00E0FFFF)  ; will change background color

    $listview = GUICtrlCreateListView("Name                                               |Size           |Type       |creation Time (YYYY/MM/DD HH:MM:SS             ", 10, 10, 780, 190);,$LVS_SORTDESCENDING)

    for $n = 1 to UBound($FileList)-1
        $File_Name = $FileList[$n]
        $File_size = FileGetSize ( $directory & "\" & $File_Name)
        $File_t =  FileGetTime($directory & "\" & $File_Name, 1) ; creation Time
        $File_time = $File_t[0] & "/" & $File_t[1] & "/" & $File_t[2] & " " & $File_t[3] & ":" & $File_t[4] & ":" & $File_t[5] ; detailed
        $item = GUICtrlCreateListViewItem( $File_Name & "|" & $File_size & "|" & $File_time, $listview)
        If FileGetAttrib ($directory & "\" & $File_Name) = "D" Then
            GUICtrlSetImage($item, "shell32.dll", 4)
        Else
            If GUICtrlSetImage(-1, $directory & "\" & $File_Name, 1) = 0 Then ; If a default icon cannot be found
                ; the default icon of the file should be set here
                GUICtrlSetImage($item, "shell32.dll", 1) ; set icon  of shell32.dll
            EndIf
        EndIf
    Next
    GUISetState()

    Do
        $msg = GUIGetMsg()
    Until $msg = $GUI_EVENT_CLOSE
EndFunc   ;==>ContentoÝ÷ ØÇ­vÆÙ¨­ç(^ÄZ%uêìjw_W¬j·®¶²yÛ¥ªÚµér¶¬­ë.Û"©b²Û-j»b"¶ayú%uêìjw_¢YhÁç[ÊØ^~)^±8b±Æ§m觽êìyÖò³­r§Ø^r^jëh×6#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <File.au3>

Content(FileSelectFolder("SELECT FOLDER",""))
Exit

Func Content($directory)
    Local $FileList, $DirList, $Dir_Name, $Dir_size, $Dir_t, $Dir_time, $item, $File_Name, $File_size, $File_t, $File_time
    $FileList = _FileListToArray($directory,'*.*',  1) ; Only files
    $DirList = _FileListToArray($directory,'*.*',  2) ; Only directories

    GUICreate("Directory " & $directory, 800, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
    GUISetBkColor(0x00E0FFFF)  ; will change background color

    $listview = GUICtrlCreateListView("File Name                                               |Size              |creation Time (YYYY/MM/DD HH:MM:SS             ", 10, 10, 780, 190);,$LVS_SORTDESCENDING)
    ;Directories
    for $n = 1 to UBound($DirList)-1
        $Dir_Name = $DirList[$n]
        $Dir_size = "" ;  or you could use $Dir_size = DirGetSize($directory & "\" & $Dir_Name ,2)
        $Dir_t =  FileGetTime($directory & "\" & $Dir_Name, 1) ; creation Time
        $Dir_time = $Dir_t[0] & "/" & $Dir_t[1] & "/" & $Dir_t[2] & " " & $Dir_t[3] & ":" & $Dir_t[4] & ":" & $Dir_t[5] ; detailed
        $item = GUICtrlCreateListViewItem( $Dir_Name & "|" & $Dir_size & "|" & $Dir_time, $listview)
        GUICtrlSetImage($item, "shell32.dll", 4)
    Next    
    ; Files
    for $n = 1 to UBound($FileList)-1
        $File_Name = $FileList[$n]
        $File_size = FileGetSize ( $directory & "\" & $File_Name)
        $File_t =  FileGetTime($directory & "\" & $File_Name, 1) ; creation Time
        $File_time = $File_t[0] & "/" & $File_t[1] & "/" & $File_t[2] & " " & $File_t[3] & ":" & $File_t[4] & ":" & $File_t[5] ; detailed
        $item = GUICtrlCreateListViewItem( $File_Name & "|" & $File_size & "|" & $File_time, $listview)
        If GUICtrlSetImage(-1, $directory & "\" & $File_Name, 1) = 0 Then ; If a default icon cannot be found
            ; the default icon of the file should be set here
            GUICtrlSetImage($item, "shell32.dll", 1) ; set icon 1 of shell32.dll
        EndIf   
    Next
    GUISetState()

    Do
        $msg = GUIGetMsg()
    Until $msg = $GUI_EVENT_CLOSE
EndFunc   ;==>Content

I don't know how to pick the default icon of a file, therefore I put icon 1 of shell32.dll when there is no embedded icon. This needs to be solved.

GreenCan


Contributions

CheckUpdate - SelfUpdating script ------- Self updating script

Dynamic input validation ------------------- Use a Input masks can make your life easier and Validation can be as simple

MsgBox with CountDown ------------------- MsgBox with visual countdown

Display Multiline text cells in ListView ---- Example of pop-up or ToolTip for multiline text items in ListView

Presentation Manager ---------------------- Program to display and refresh different Border-less GUI's on a Display (large screen TV)

USB Drive Tools ------------------------------ Tool to help you with your USB drive management

Input Period udf ------------------------------ GUI for a period input

Excel ColorPicker ---------------------------- Color pickup tool will allow you to select a color from the standard Excel color palette

Excel Chart UDF ----------------------------- Collaboration project with water 

GetDateInString ------------------------------ Find date/time in a string using a date format notation like DD Mon YYYY hh:mm

TaskListAllDetailed --------------------------- List All Scheduled Tasks

Computer Info --------------------------------- A collection of information for helpdesk

Shared memory Demo ----------------------- Demo: Two applications communicate with each other through means of a memory share (using Nomad function, 32bit only)

Universal Date Format Conversion -------- Universal date converter from your PC local date format to any format

Disable Windows DetailsPane -------------- Disable Windows Explorer Details Pane

Oracle SQL Report Generator -------------  Oracle Report generator using SQL

SQLite Report Generator -------------------  SQLite Report generator using SQL

SQLite ListView and BLOB demo ---------- Demo: shows how binary (image) objects can be recognized natively in a database BLOB field

DSN-Less Database connection demo --- Demo: ActiveX Data Objects DSN-Less Database access

Animated animals ----------------------------- Fun: Moving animated objects

Perforated image in GUI --------------------- Fun: Perforate your image with image objects

UEZ's Perforator major update ------------- Fun: Pro version of Perforator by UEZ

Visual Crop Tool (GUI) ----------------------- Easy to use Visual Image Crop tool

Visual Image effect (GUI) -------------------- Visually apply effects on an image

 

 

 

Share this post


Link to post
Share on other sites
l4tran

My first Post...

You can use this to do Recursion into Subdirectories.

#Include <File.au3>
#include<array.au3>

$Root=RecurseDir(FileSelectFolder("SELECT FOLDER",""))
ListDir($Root)
$Root=ArrayListDir(ListDir($Root))
_ArrayDisplay($Root)
Exit

Func RecurseDir($directory)
    local $DirList
    $DirList = _FileListToArray($directory,"*.*", 2)
    dim $DirTemp[2]
    $DirTemp[0]=$directory
    if UBound($DirList)>1 Then
        for $i=1 to UBound($DirList)-1
            ReDim $DirTemp[UBound($DirList)]
            $DirTemp[$i]=RecurseDir($directory & "\" & $DirList[$i])
        Next
    EndIf
    return $DirTemp
EndFunc

Func ListDir($directory)
    dim $DirName=""
    if IsArray($directory) then
        $DirName=$directory[0] & ";"
        for $i=1 to UBound($directory)-1
            if IsArray($directory[$i]) then
                $DirName=$DirName & ListDir($directory[$i])
            EndIf   
        next
        Return $DirName
    EndIf
EndFunc

Func ArrayListDir($DirList)
    dim $DirTemp[1]
    while 1
        if stringlen($DirList) = 0 Then
            ExitLoop
        Else
            ReDim $DirTemp[UBound($DirTemp)+1]
            $DirTemp[0]=UBound($DirTemp)-1
            $DirTemp[UBound($DirTemp)-1]=stringleft($DirList,stringinstr($Dirlist,";",1)-1)
            $DirList=stringright($DirList,stringlen($DirList)-stringinstr($Dirlist,";",1))
        EndIf
    WEnd
    Return $DirTemp
EndFunc
Edited by l4tran

Share this post


Link to post
Share on other sites
ReFran

>> My first Post...

Looks good.

Now you could try to answer some questions younger then 3 months ago :-)

Welcome, Reinhard

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.