Skip to content

list_filesListFilesListFileslist_filesT_list_files🔗

Short description🔗

list_filesListFilesListFileslist_filesT_list_files — List all files in a directory.

Signature🔗

list_files( filename.dir Directory, string Options, out string Files )void ListFiles( const HTuple& Directory, const HTuple& Options, HTuple* Files )static void HOperatorSet.ListFiles( HTuple directory, HTuple options, out HTuple files )def list_files( directory: str, options: MaybeSequence[str] ) -> Sequence[str]

Herror T_list_files( const Htuple Directory, const Htuple Options, Htuple* Files )

static HTuple HMisc::ListFiles( const HString& Directory, const HTuple& Options )

static HTuple HMisc::ListFiles( const HString& Directory, const HString& Options )

static HTuple HMisc::ListFiles( const char* Directory, const char* Options )

static HTuple HMisc::ListFiles( const wchar_t* Directory, const wchar_t* Options ) (Windows only)

static HTuple HMisc.ListFiles( string directory, HTuple options )

static HTuple HMisc.ListFiles( string directory, string options )

Description🔗

list_filesListFiles returns all files in the directory given by Directorydirectorydirectory in the parameters Filesfilesfiles. The current directory can be specified with ''"" or '.'".". The parameter Optionsoptionsoptions can be used to specify different processing options by passing a tuple of values.

If Optionsoptionsoptions contains 'files'"files" only the files present in Directorydirectorydirectory are returned. If 'directories'"directories" is passed, only the directories present in Directorydirectorydirectory are returned. On Unix-like systems 'symlinks'"symlinks" may be passed to list symbolic links. Directories are marked by a trailing ‘' (Windows) or a trailing ’/’ (Unix-like systems). If files as well as directories should be returned, ['files', 'directories']["files", "directories"] must be passed. If none of 'files'"files", 'directories'"directories" or 'symlinks'"symlinks" is passed, list_filesListFiles returns an empty tuple.

By passing 'recursive'"recursive", it can be specified that the directory tree should be searched recursively by examining all sub-directories. On Unix-like systems, 'follow_links'"follow_links" can be used to specify that symbolic links to files or directories should be followed. In the default setting, symbolic links are not dereferenced, and hence are not searched if they point to directories, and not returned if they point to files. The option 'follow_links'"follow_links" can not be used in conjunction with the option 'symlinks'"symlinks".

For the recursive search, a maximum search depth can be specified with ‘max_depth ‘, where ‘‘ is a number that specifies the maximum depth. Hence, 'max_depth 2'"max_depth 2" specifies that Directorydirectorydirectory and all immediate sub-directories should be searched. If symbolic links should be followed it might happen that the search does not terminate if the symbolic links lead to a cycle in the directory structure. Because of this, at most 1000000 files (and directories) are returned in Filesfilesfiles. By specifying a different number with ‘max_files ‘, this value can be modified.

Execution information🔗

Execution information
  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Processed without parallelization.

Parameters🔗

Directorydirectorydirectory (input_control) filename.dir → (string)HTuple (HString)HTuple (string)strHtuple (char*)

Name of directory to be listed.

Optionsoptionsoptions (input_control) string(-array) → (string)HTuple (HString)HTuple (string)MaybeSequence[str]Htuple (char*)

Processing options.

Default: 'files'"files"
Suggested values: 'files', 'directories', 'symlinks', 'recursive', 'follow_links', 'max_depth 5', 'max_files 1000'"files", "directories", "symlinks", "recursive", "follow_links", "max_depth 5", "max_files 1000"

Filesfilesfiles (output_control) string-array → (string)HTuple (HString)HTuple (string)Sequence[str]Htuple (char*)

Found files (and directories).

Result🔗

list_filesListFiles returns the value 2 (H_MSG_TRUE) if the directory exists and could be read. Otherwise, an exception is raised.

Combinations with other operators🔗

Combinations

Possible successors

tuple_regexp_selectTupleRegexpSelect

Module🔗

Foundation