Extensions.File.GetFilesFromDirectory

From emotive
Jump to navigation Jump to search

Classification

Name GetFilesFromDirectory
Short Description Returns a list with the files in the specified directory
Class Term
Extension OTX File extension
Group File related Terms
Exceptions FileAccessException
FileNotFoundException
Checker Rules -
Standard Compliant Yes

OTL Syntax

ListTerm File.GetFilesFromDirectory(StringTerm path, StringTerm searchPattern, BooleanTerm includeSubDirectories);

Description

The GetFilesFromDirectory activity returns a list of strings with the paths as URIs of the files in the specified directory that match the specified search pattern. Paths are either absolute or relative to OTX home.

Given the following example file system contents:

  • file:///usr/user1/example1.txt
  • file:///usr/user1/example/example.txt
  • file:///usr/user1/example/example1.txt
  • file:///usr/user1/example/example2.txt

GetFilesFromDirectory(“file:///usr/user1”, “*.txt”, true) will return the paths of all four files.

GetFilesFromDirectory(“file:///usr/user1/”, “example?.txt”, true) will return the paths of example0.txt, example1.txt and example2.txt.

GetFilesFromDirectory(“file:///usr/user1”, “example/*.txt”, true) will return an empty list, as the search pattern may only be used to match file names, not directory names.

Return Value

The Term returns the value, see table below.

Icons Note.png In OTX, Terms are categorized according to its return data type!
Data Type Description
List Returns a list of strings with the paths as URIs of the files in the specified directory that match the specified search pattern.

Properties

Name Data Type Class Default Cardinality Description
IncludeSubDirectories Boolean Term - [0..1] If the parameter is TRUE, all files within subdirectories in any depth shall also returned. Default = TRUE.
Path String Term - [1..1] The directory to scan. The path parameter is permitted to specify relative or absolute path information.
SearchPattern String Term - [0..1] The search string to match against file names. It shall only be matched against the file name itself, not against directory names within the path. The following wildcard specifiers are permitted in the searchPattern: "*" = Zero or more characters; "?" = Exactly one character. Characters other than the wildcard specifiers represent themselves.For example, the searchPattern string "*t" searches for all names in path ending with the letter "t". The searchPattern string "s*" searches for all names in path beginning with the letter "s".

OTL Examples

/// Local Declarations

File.FileWriteHandle FileWriteHandle1;
String String1 = "";
List<String> List_String;

/// Flow

String1 = File.CreateTempDirectory();
FileWriteHandle1 = File.OpenFileForWrite(StringUtil.StringConcatenate({String1, "/abc.txt"}), false, @Encoding:UTF-8);
List_String = File.GetFilesFromDirectory(String1, "*.txt", true);

See also

CreateTempDirectory
GetFilePath
GetFileSize
IsDirectory
IsEndOfFileReached
IsFile
OpenFileForRead
OpenFileForWrite
ReadBytes
ReadFile
ReadLine