Stata 15 help for mata_dir

[M-5] dir() -- File list

Syntax

string colvector dir(dirname, filetype, pattern)

string colvector dir(dirname, filetype, pattern, prefix)

where

dirname: string scalar containing directory name

filetype: string scalar containing "files", "dirs", or "other"

pattern: string scalar containing match pattern

prefix: real scalar containing 0 or 1

Description

dir(dirname, filetype, pattern) returns a column vector containing the names of the files in dir that match pattern.

dir(dirname, filetype, pattern, prefix) does the same thing but allows you to specify whether you want a simple list of files (prefix=0) or a list of filenames prefixed with dirname (prefix!=0). dir(dirname, filetype, pattern) is equivalent to dir(dirname, filetype, pattern, 0).

pattern is interpreted by [M-5] strmatch().

Remarks

Examples:

dir(".", "dirs", "*") returns a list of all directories in the current directory.

dir(".", "files", "*") returns a list of all regular files in the current directory.

dir(".", "files", "*.sthlp") returns a list of all *.sthlp files found in the current directory.

Conformability

dir(dirname, filetype, pattern, prefix): dirname: 1 x 1 filetype: 1 x 1 pattern: 1 x 1 prefix: 1 x 1 (optional) result: k x 1, k number of files matching pattern

Diagnostics

dir(dirname, filetype, pattern, prefix) returns J(0,1,"") if

1. no files matching pattern are found,

2. directory dirname does not exist, or

3. filetype is misspecified (is not equal to "files", "dirs", or "others").

dirname may be specified with or without the directory separator on the end.

dirname = "" is interpreted the same as dirname = "."; the current directory is searched.

Source code

Function is built in.


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index