librosa.util.find_files¶
- librosa.util.find_files(directory, *, ext=None, recurse=True, case_sensitive=False, limit=None, offset=0)[source]¶
Get a sorted list of (audio) files in a directory or directory sub-tree.
- Parameters
- directorystr
Path to look for files
- extstr or list of str
A file extension or list of file extensions to include in the search.
Default:
['aac', 'au', 'flac', 'm4a', 'mp3', 'ogg', 'wav']
- recurseboolean
If
True
, then all subfolders ofdirectory
will be searched.Otherwise, only
directory
will be searched.- case_sensitiveboolean
If
False
, files matching upper-case version of extensions will be included.- limitint > 0 or None
Return at most
limit
files. IfNone
, all files are returned.- offsetint
Return files starting at
offset
within the list.Use negative values to offset from the end of the list.
- Returns
- fileslist of str
The list of audio files.
Examples
>>> # Get all audio files in a directory sub-tree >>> files = librosa.util.find_files('~/Music')
>>> # Look only within a specific directory, not the sub-tree >>> files = librosa.util.find_files('~/Music', recurse=False)
>>> # Only look for mp3 files >>> files = librosa.util.find_files('~/Music', ext='mp3')
>>> # Or just mp3 and ogg >>> files = librosa.util.find_files('~/Music', ext=['mp3', 'ogg'])
>>> # Only get the first 10 files >>> files = librosa.util.find_files('~/Music', limit=10)
>>> # Or last 10 files >>> files = librosa.util.find_files('~/Music', offset=-10)