Jump to content

List files in a folder


Recommended Posts

The following code lists all files & folders in the current directory. I was thinking of creating a counter, increase it every time a tree view item is added. Then in a for loop, check each item with a IsFolder() function, but there isn't a function that I'm aware of that does that.

#include <GUIConstantsEx.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>

Local $frmMain = GUICreate("Tree View", 234, 363, -1, -1)
Local $tMain = GUICtrlCreateTreeView(0, 0, 250, 380)

$hFiles = FileFindFirstFile("*.*")
If $hFiles = -1 Then Exit

While 1
    $cFile = FileFindNextFile($hFiles)
    If @error Then ExitLoop
    GUICtrlCreateTreeViewItem($cFile, $tMain)
WEnd
FileClose($hFiles)
GUISetState(@SW_SHOW)

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

    EndSwitch
WEnd
Link to comment
Share on other sites

You can use the @extended macro to check whether it is a folder!

...
$cFile = FileFindNextFile($hFiles)
If @extended then ConsoleWrite("Found a dir" & @CRLF)
...

BR,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Another way would be using Function _FileListToArray_FileListToArray with its parameter.

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

  • 4 months later...

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