DirectoryRead
Function Block - Reads the next entry from an open directory.
- The directory must first be opened with DirectoryOpen.
- Entries are filtered according to the
OptionsandFiltersupplied toDirectoryOpen. - Each successful execution returns information about a single directory entry through the Entry output.
- Repeatedly execute
DirectoryReadon the same directory ID to iterate over all entries. - When there are no more entries, ListDone is set to TRUE and the Entry output is not updated.
Inputs
|
Input |
Data Type See Data Types. |
Range |
Unit |
Default |
Description |
|---|---|---|---|---|---|
|
Execute |
BOOL |
FALSE, TRUE |
N/A |
No default |
On the rising edge, read the next directory entry. |
|
ID |
UDINT |
No range |
N/A |
No default |
The ID of the open directory returned by DirectoryOpen. |
|
Entry |
DIR_ENTRY |
No range |
N/A |
No default |
|
Outputs
|
Output |
Data Type See Data Types. |
Range |
Unit |
Description |
|---|---|---|---|---|
|
Done |
BOOL |
FALSE, TRUE |
N/A |
If TRUE, the command completed successfully. |
|
Error |
BOOL |
FALSE, TRUE |
N/A |
If TRUE, an error has occurred. |
|
ErrorID |
DINT |
Enumerated |
N/A |
|
|
ListDone |
BOOL |
FALSE, TRUE |
N/A |
|
DIR_ENTRY Structure
|
Member |
Data Type |
Description |
|---|---|---|
|
Name |
STRING(255) |
The name of the entry (file or subdirectory), without the directory path. |
|
IsDirectory |
BOOL |
|
|
Size |
ULINT |
|
|
ModifyTime |
LDT |
The last modification time of the entry. |
FBD Language Example
FFLD Language Example
IL Language Example
Not available.
ST Language Example
CASE StepCounter OF
0: Inst_DirectoryOpen(TRUE, 'logs', '*.log', DIR_OPTION_FILES + DIR_OPTION_GLOB); IF Inst_DirectoryOpen.Done THEN
MyDirID := Inst_DirectoryOpen.ID; Inst_DirectoryOpen(FALSE, '', '', 0); StepCounter := StepCounter + 1;
END_IF; 1:
Inst_DirectoryRead(TRUE, MyDirID); StepCounter := StepCounter + 1; 2: Inst_DirectoryRead(TRUE, MyDirID);
IF Inst_DirectoryRead.Done THEN
IF Inst_DirectoryRead.ListDone THEN
// No more entries - move on to next step closing the directory Inst_DirectoryRead(FALSE, 0); StepCounter := StepCounter + 1; ELSE
EntryName := Inst_DirectoryRead.Entry.Name; IsDir := Inst_DirectoryRead.Entry.IsDirectory;
// Keep StepCounter unchanged so that return and read the next entry
Inst_DirectoryRead(FALSE, 0); END_IF; END_IF; 3: Inst_DirectoryClose(TRUE, MyDirID); StepCounter := StepCounter + 1; 4:
Inst_DirectoryClose(TRUE, MyDirID);
IF Inst_DirectoryClose.Done THEN
Inst_DirectoryClose(FALSE, 0); StepCounter := StepCounter + 1; END_IF; END_CASE;







