Skip to main content

1E 23.11 (SaaS)

FileSystem.GetFilesInDirectory

Method

GetFilesInDirectory

Module

FileSystem

Library

Core

Action

Returns the filename, size, created time and modified time of each file in a directory.

Parameters

Directory (string): Full path of the directory whose contents will be returned

Recursive (boolean; optional, default true): Whether or not to return the contents of subdirectories.

Limit (integer, optional, default 8192): Return no more than this number of files; 0 means all files (i.e. no limit).

Exclude (Table, optional): A single column table where each row contains a directory path relative to the 'Directory' parameter that you want to exclude from recursive search.

Note

On Windows a remote directory is not supported as a mapped drive, although UNC format does work.

Ensure that the exclude paths are relative to the directory parameter.

Return values

If Directory does not exist (which can happen if the path format is not suitable for the device's operating system) or it is actually a file then an error status is returned with a suitable error message.

If Directory itself cannot be opened (exceptions will be logged by the agent) or no files are found then this is considered a successful execution but no results are returned.

If Directory itself can be opened and Recursive is true but then a subdirectory or file cannot be accessed then those items will be skipped in the results (and the Agent will log warnings).

Otherwise if any files are found then the result returned for each will have this form:

  • FileName (string): The full path of the file

  • FileSize (int): The size of the file in bytes

  • DateCreated (string): The creation date of the file

  • DateModified (string): The last modified date of the file

Example

 FileSystem.GetFilesInDirectory(Directory:"c:\\tmp");
 FileSystem.GetFilesInDirectory(Directory:"c:\\tmp", Recursive:false);
@exclude =
SELECT
        column1 AS Path
FROM
        ( VALUES
                (".\\tmp1"),
                (".\\tmp2\\SubFolder")
        );

FileSystem.GetFilesInDirectory(Directory:"C:\\tmp",Exclude:@exclude);

Platforms

  • Windows

  • Linux

  • MacOS

Notes

The DateCreated concept does not exist on some operating systems and consequently this field will be blank where it does not apply.

Where the agent cannot access the directory itself then the instruction will return ExcutionError.

Important

OneDrive can report a file creation time after the last modified time.