directory

directory — Reads a directory and outputs to a string array a list of file names.

Description

Reads a directory for files and passes them to a string array. Users can set the file type by passing a file extension as a string.

Syntax

SFiles[] directory SDirectory[, SExtention]

Initialization

SDirectory -- a string that identifies the directory to browse for files

SExtention -- Optional. Sets the desired file type. If left out, all files names will be retrieved.

Performance

SFiles[] -- a string array that holds the names of all files of a given type found in the directory.

[Note] Note

This works at i-time only and will not pick up changes made to the directory after performance has started.

Example

This example shows how directory can be used to browse for .wav files in a fixed location. printf_i is then used to print the file names. It uses the file directory.csd.

Example 235. Example of the directory opcode.

<CsoundSynthesizer>
<CsOptions>
-n
</CsOptions>
<CsInstruments>

;browse for text files in current directory
instr 1
iCnt init 0
SFilenames[] directory ".", ".txt"
iNumberOfFiles lenarray SFilenames

until iCnt>=iNumberOfFiles do
	printf_i "Filename = %s \n", 1, SFilenames[iCnt]
	iCnt = iCnt+1
od
endin

</CsInstruments>
<CsScore>
i1 0 1
</CsScore>
</CsoundSynthesizer>


Credits

Author: Rory Walsh
2016