Jump to content
Sign in to follow this  

Scan folders and subfolders and list files only

Recommended Posts


I found here the following code.

In the array are listed all folders and files.

How to modify the code that the names of the subfolders are not listed.

The path of the file is fine, there the subfolder can be displayed.


Local $aRetArray
Local $path = "D:\tmp"
Local $sFindFile = "*"
Local $sRet

;$aRetArray = _FindPathName($path, $sFindFile)

$sRet = ""
$aRetArray = _FindPathName($path, $sFindFile)

; Funktion
Func _FindPathName($sPath, $sFindFile)
Local $sSubFolderPath, $iIndex, $aFolders, $search,$aFoldersSubs
$search = FileFindFirstFile($sPath & "\" & $sFindFile)
$aFolders = _FileListToArray($sPath, "*", 2)

While 1
$file = FileFindNextFile($search)
If @error Then
$sRet &= $sPath & "\" & $file & "|"


For $iIndex = 1 To $aFolders[0]
$sSubFolderPath = $sPath & "\" & $aFolders[$iIndex]
$aFoldersSubs = _FileListToArray($sSubFolderPath, "*", 2)
If IsArray($aFoldersSubs) Then _FindPathName($sSubFolderPath, $sFindFile)

Return StringSplit(StringTrimRight($sRet,1), "|")

Share this post

Link to post
Share on other sites

Here an alternate solution.

#include <file.au3>
#include <array.au3>

Func __FileListToArray($path)
Local $array[1]=[0], $tempfile = _TempFile()
RunWait(@ComSpec & " /c dir /S /B /A-D /ON " & $path & " > " & $tempfile, "", @SW_HIDE)
_FileReadToArray($tempfile, $array)
Return $array
EndFunc ;==>__FileListToArray

$myArray = __FileListToArray(@ScriptDir & "\*.exe " & @ScriptDir & "\*.au3 ")

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

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.