Navigation: thinBasic Modules > File > DIR_ListArray |
|
Description
Fill an array variable with the list of files found in the specified path having the requested characteristics.
Function will also return number of files found.
Syntax
nFiles = DIR_ListArray(StringArrayVariable, Path, Mask, [Attribute, [Options]])
Returns
Number: number of files found.
Parameters
Name |
Type |
Optional |
Meaning |
StringArrayVariable |
String |
No |
An already defined string array variable |
Path |
String |
No |
Path to search into. Examples: "C:\Temp\" "C:\"
|
Mask |
String |
No |
Specifies a filename or additional sub path which can include a drive name and DOS compatible wildcard characters (* and ?). Examples: "*.*" "*.TXT"
|
Attribute |
Numeric |
Yes |
See File Equates for possible attributes. Examples: %FILE_NORMAL Or %FILE_ADDPATH %FILE_SYSTEM Or %FILE_HIDDEN Or %FILE_ADDPATH
Attention: %FILE_ADDPATH do not work alone but must be always used in conjunction with another attribute. |
Options |
Numeric |
Yes |
Not used. Possible future usage. |
Remarks
This function will automatically dimension StringArrayVariable based on the number of files found.
If no files will be found, in any case StringArrayVariable will be dimensioned to 1 but function will return zero.
Restrictions
See also
Examples
Sample script
USES "FILE"
Dim MyList() As String
Dim nFiles As Long
nFiles = DIR_ListArray(MyList, "C:\Temp\", "*.*", %FILE_ADDPATH)
MSGBOX 0, "Number of files found: " & nFiles
'---MyList will now contains the list of files found
Thanks to Abraxas for the following script example
USES "UI"
USES "FILE"
Dim SelectedDIR As String ' The directory that we want to scan
Dim TheFileList() As String ' The Filename Table
Dim FileLength() As DWORD ' The File Length Table
Dim NumberofFiles As DWORD ' The Number of files in the list
Dim n As Long ' Loop Variable
Dim sMsg As String ' Message String
SelectedDIR = DIALOG_BrowseForFolder(0, "Please select a directory", "C:\", %False)
If SelectedDIR <> "" Then
NumberofFiles = DIR_ListArray(TheFileList, SelectedDIR, "*.*", %FILE_NORMAL Or %FILE_ADDPATH)
' Fill File Length Table
ReDim FileLength(NumberofFiles) ' Allocate space for File Length Table
For n = 1 To NumberofFiles
FileLength(n) = File_SIZE (TheFileList(n))
Next
sMsg = "Number of files found: " & NumberofFiles & $CRLF & $CRLF
sMsg += "First 10 files are:" & $CRLF & $CRLF
sMsg += JOIN$(TheFileList, $CRLF, "", 1, 10) ' add only 10 files to list
Else
sMsg += "No selected folder. Operation not performed."
End If
MSGBOX 0, sMsg
© 2004-2008 thinBasic. All rights reserved. | Version 1.7.0.0 | Web Site: http://www.thinbasic.com |