Opcodes
cabbageCreateFileName
Generates a likely-unique filename in a target directory using the requested extension. This opcode is useful when you need a valid and unique filename for testing. The opcode returns a full path (forward slashes) but does not create the file on disk. This opcode is i-time only, so it’s best used in a dedicated instrument that will generate the filename when needed.
Syntax
Section titled “Syntax”filename:i = cabbageCreateFileName(SDirectory, SExtension)Initialization
Section titled “Initialization”SDirectory– string: Target directory for the new filename. May be absolute or relative to the current CSD.SExtension– string: File extension including the leading dot, e.g..json.
The opcode returns a single string containing a full path that is intended not to collide with existing files in directory.
Example
Section titled “Example”ksmps = 32nchnls = 20dbfs = 1
instr 1 dir:S = chnget("USER_DOCUMENTS_DIRECTORY") fname:S = cabbageCreateFileName(dir, ".json") prints("New filename: %s\n", fname)endin- The returned filename is not created by this opcode; use standard file IO to write data to the path if desired.
- Use reserved
USER_*_DIRECTORYchannels to choose platform-appropriate storage locations.