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 (
Union
[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 = mkdir("path") >>> _ = touch(dir_path, "file.wav") >>> _ = touch(dir_path, "File.wav") >>> _ = touch(dir_path, ".lock") >>> sub_dir_path = mkdir("path", "sub") >>> _ = touch(sub_dir_path, "file.ogg") >>> _ = touch(sub_dir_path, ".lock") >>> list_file_names( ... dir_path, ... basenames=True, ... ) ['File.wav', 'file.wav'] >>> list_file_names( ... dir_path, ... basenames=True, ... hidden=True, ... ) ['.lock', 'File.wav', 'file.wav'] >>> list_file_names( ... dir_path, ... basenames=True, ... recursive=True, ... ) ['File.wav', 'file.wav', 'sub/file.ogg'] >>> list_file_names( ... dir_path, ... basenames=True, ... recursive=True, ... hidden=True, ... ) ['.lock', 'File.wav', 'file.wav', 'sub/.lock', 'sub/file.ogg'] >>> list_file_names( ... os.path.join(dir_path, "f*"), ... basenames=True, ... recursive=True, ... hidden=True, ... ) ['file.wav', 'sub/file.ogg'] >>> list_file_names( ... os.path.join(dir_path, "[fF]*"), ... basenames=True, ... recursive=True, ... hidden=True, ... ) ['File.wav', 'file.wav', 'sub/file.ogg'] >>> list_file_names( ... os.path.join(dir_path, "[!f]*"), ... basenames=True, ... recursive=True, ... hidden=True, ... ) ['.lock', 'File.wav', 'sub/.lock'] >>> list_file_names( ... os.path.join(dir_path, "f*"), ... filetype="ogg", ... basenames=True, ... recursive=True, ... hidden=True, ... ) ['sub/file.ogg']