list_file_names()¶
- audeer.list_file_names(path, *, filetype='', basenames=False, recursive=False, hidden=False)[source]¶
List of file names inferred from provided path.
- Parameters
path (
str
|bytes
) – path to directory, or path to directory plus file matching pattern, e.g.'dir/file.txt'
. Ifrecursive
isTrue
returns all files namedfile.txt
from all sub-folders. Besides the filename*
,?
,[seq]
, and[!seq]
can be used as pattern, comparefnmatch
filetype (
str
) – optional consider only this filetypebasenames (
bool
) – ifTrue
return relative path in respect topath
recursive (
bool
) – ifTrue
includes subdirectorieshidden (
bool
) – ifTrue
includes files starting with a dot (.
)
- Return type
- Returns
alphabetically sorted list of path(s) to file(s)
- Raises
NotADirectoryError – if
path
is a directory or file that does not exist, orpath
is a pattern andos.dirname(path)
does not exist
Examples
>>> dir_path = audeer.mkdir("path") >>> _ = audeer.touch(dir_path, "file.wav") >>> _ = audeer.touch(dir_path, "album.wav") >>> _ = audeer.touch(dir_path, ".lock") >>> sub_dir_path = audeer.mkdir(dir_path, "sub") >>> _ = audeer.touch(sub_dir_path, "file.ogg") >>> _ = audeer.touch(sub_dir_path, ".lock") >>> audeer.list_file_names(dir_path, basenames=True) ['album.wav', 'file.wav'] >>> audeer.list_file_names(dir_path, basenames=True, hidden=True) ['.lock', 'album.wav', 'file.wav'] >>> audeer.list_file_names(dir_path, basenames=True, recursive=True) ['album.wav', 'file.wav', 'sub/file.ogg'] >>> audeer.list_file_names(dir_path, basenames=True, recursive=True, hidden=True) ['.lock', 'album.wav', 'file.wav', 'sub/.lock', 'sub/file.ogg'] >>> audeer.list_file_names( ... os.path.join(dir_path, "f*"), basenames=True, recursive=True ... ) ['file.wav', 'sub/file.ogg'] >>> audeer.list_file_names( ... os.path.join(dir_path, "[fa]*"), basenames=True, recursive=True ... ) ['album.wav', 'file.wav', 'sub/file.ogg'] >>> audeer.list_file_names( ... os.path.join(dir_path, "[!f]*"), basenames=True, recursive=True ... ) ['album.wav'] >>> audeer.list_file_names(dir_path, filetype="ogg", basenames=True, recursive=True) ['sub/file.ogg']