User-Defined Opcode Database

FilDir

returns the directory of a file path

Download UDO File

Description

returns the directory part of a given file path string, at i-rate (csound 5.15 or higher)

Syntax

Sdir FilDir Spath

Initialization

Spath - full path as string
Sdir - directory

Code

  opcode FilDir, S, S
Spath      xin
ipos      strrindex Spath, "/"
Sdir      strsub    Spath, 0, ipos
          xout      Sdir
  endop

Examples

<CsoundSynthesizer>
<CsOptions>
-m0
</CsOptions>
<CsInstruments>
  
  opcode FilDir, S, S
;returns the directory of a file path
Spath      xin
ipos      strrindex Spath, "/"
Sdir      strsub    Spath, 0, ipos
          xout      Sdir
  endop
  
  instr dir
          prints    "Printing directory:\n"
Sdir      FilDir    "/my/dir/my/file.WAV"
          puts      Sdir, 1  
  endin
  
</CsInstruments>
<CsScore>
i "dir" 0 0
</CsScore>
</CsoundSynthesizer>

Credits

joachim heintz 2012


Previous Home Next
GaussTrig   FilNam