DirectoryRead

PLCopen motion icon

 Function Block - Reads the next entry from an open directory.

  • The directory must first be opened with DirectoryOpen.
  • Entries are filtered according to the Options and Filter supplied to DirectoryOpen.
  • Each successful execution returns information about a single directory entry through the Entry output.
  • Repeatedly execute DirectoryRead on 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

  • The directory entry to be filled.
  • Only valid when Done is TRUE and ListDone is FALSE.
  • See DIR_ENTRY Structure.

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

  • If TRUE, all entries have been read and no further entries are available.
  • When ListDone is TRUE, the Entry output is not updated.

DIR_ENTRY Structure

Member

Data Type

Description

Name

STRING(255)

The name of the entry (file or subdirectory), without the directory path.

IsDirectory

BOOL

  • TRUE if the entry is a subdirectory.
  • FALSE if it is a regular file.

Size

ULINT

  • The size of the entry in bytes.
    • Valid for files.
    • 0 (zero) for directories.

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;