Code: (Select All)
$Console:Only
ReDim Shared As String FileList(0), DirList(0)
Disk.File.List "", "" 'get a list of all files in the root directory
Disk.Dir.List "C:", "U*" 'get a list of all subdirectories that start with "U" from the root directory
For i = 1 To UBound(FileList)
Print i, FileList(i)
Next
Sleep
_Delay .5
Cls
_KeyClear
For i = 1 To UBound(DirList)
Print i, DirList(i)
Next
Sleep
System
Sub Disk.File.List (SearchDirectory As String, Extension As String)
Dim As Long FileCount
Dim As String Search, File, slash
ReDim _Preserve FileList(1000) As String
If SearchDirectory = "" Then SearchDirectory = _CWD$
$If WIN Then
slash = "\"
$Else
Slash = "/"
$End If
If Right$(SearchDirectory, 1) <> "/" _AndAlso Right$(SearchDirectory, 1) <> "\" Then SearchDirectory = SearchDirectory + slash
If Extension = "" Then Extension = "*"
Search = SearchDirectory + Extension
File = _Files$(Search)
Do While Len(File)
File = SearchDirectory + File
If _FileExists(File) Then
FileCount = FileCount + 1
If FileCount > UBound(FileList) Then ReDim _Preserve FileList(FileCount + 1000) As String
FileList(FileCount) = File
End If
File = _Files$
Loop
ReDim _Preserve FileList(FileCount) As String
End Sub
Sub Disk.Dir.List (SearchDirectory As String, SearchFor As String)
Dim As Long DirCount
Dim As String Search, Dir, Slash
ReDim _Preserve DirList(1000) As String
If SearchDirectory = "" Then SearchDirectory = _CWD$
$If WIN Then
Slash = "\"
$Else
Slash = "/"
$End If
If Right$(SearchDirectory, 1) <> "/" _AndAlso Right$(SearchDirectory, 1) <> "\" Then SearchDirectory = SearchDirectory + Slash
Search = SearchDirectory + SearchFor
Dir = _Files$(Search)
Do While Len(Dir)
Dir = SearchDirectory + Dir
If _DirExists(Dir) Then
DirCount = DirCount + 1
If DirCount > UBound(DirList) Then ReDim _Preserve DirList(UBound(DirList) + 1000) As String
DirList(DirCount) = Dir
End If
Dir = _Files$
Loop
ReDim _Preserve DirList(DirCount) As String
End Sub
Updated to make use of the new _FILES$ command so this doesn't need any external libraries or anything to run.
What it does is give you a quick listing of files or directory into a shared set of arrays called FileList() and DirList().
Usage is rather simple as shown in the demo here. If anyone has questions, feel free to ask.

EDIT: I'd suggest using the version below for extended flexibility and control over your return data. https://qb64phoenix.com/forum/showthread...2#pid39082
In my personal opinion, the version in post #7 is much better than this version, especially once you start mixing and matching how the flag return values work for you.

