ficlose — Closes a previously opened file.


ficlose can be used to close a file which was opened with fiopen.


ficlose ihandle
ficlose Sfilename


ihandle -- a number which identifies this file (generated by a previous fiopen).

Sfilename -- A string in double quotes or string variable with the filename. The full path must be given if the file directory is not in the system PATH and is not present in the current directory.


ficlose closes a file which was previously opened with fiopen. ficlose is only needed if you need to read a file written to during the same csound performance, since only when csound ends a performance does it close and save data in all open files. The opcode ficlose is useful for instance if you want to save presets within files which you want to be accesible without having to terminate csound.

[Note] Note

If you do not need this functionality it is safer not to call ficlose, and just let csound close the files when it exits.

If a files closed with ficlose is being accessed by another opcode (like fout or foutk), it will be closed later when it is no longer being used.

[Warning] Warning

This opcode should be used with care, as the file handle will become invalid, and will cause an init error when an opcode tries to access the closed file.


Here is an example of the ficlose opcode. It uses the file ficlose.csd.

Example 297. Example of the ficlose opcode.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

; Select audio/midi flags here according to platform
-odac     ;;;realtime audio out
;-iadc    ;;;uncomment -iadc if realtime audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o ficlose.wav -W ;;; for file output any platform

sr = 44100 
ksmps = 32 
nchnls = 2 
0dbfs  = 1 

gihand fiopen "test1.txt", 0 

instr 1

ires  random  0, 100
      fouti gihand, 0, 1, ires 
      ficlose gihand 


i 1 0 1 


See also

File Input and Output


Author: Gabriel Maldonado

New in Csound version 5.02