Opcodes
cabbageGetFiles
Returns a list of files in a directory optionally filtered by extension. Useful for populating file lists for widgets (e.g., comboboxes) or for scanning resource folders. This opcode works at i-time only. Therefore it is best used in an instrument that is called when the files are needed.
Syntax
Section titled “Syntax”files:S[] = cabbageGetFiles(SDirectory, SFileType)Initialization
Section titled “Initialization”SDirectory– string: The directory to search. May be an absolute path or relative to the current CSD directory.SFileType– string (optional): A single extension (e.g..json) or a semicolon-separated list (e.g..wav;.mp3). If empty, all files are returned.
The opcode returns an array of strings containing absolute file paths (forward-slash separators) matching the filter.
Example
Section titled “Example”ksmps = 32nchnls = 20dbfs = 1
instr 1 ; Get all JSON presets from the presets folder files:S[] = cabbageGetFiles("/Users/me/Presets", ".json") i = 0 while i < len(files) do prints("%s\n", files[i]) i += 1 odendin- If the directory does not exist an error is logged and an empty array is returned.
- Paths are normalized to use forward slashes (
/) regardless of platform. - Use the
USER_*_DIRECTORYreserved channels in combination with this opcode to access platform-specific folders without hardcoding paths.