User-Defined Opcode Database

FilSuf

returns the suffix of a filename or path, optional in lower case

Download UDO File

Description

returns the suffix (extension) of a filename or path, optional in lower case

Syntax

Suf FilSuf Spath,ilow

Initialization

Spath - full pathname (or filename) as string
ilow - return ensuring lower case (1) or return as in Spath (0 = default)

Code

  opcode FilSuf, S, So
Spath,ilow xin
ipos      strrindex Spath, "."
Suf       strsub    Spath, ipos+1
 if ilow != 0 then
Suf       strlower  Suf 
 endif
          xout      Suf
  endop

Examples

<CsoundSynthesizer>
<CsOptions>
-m0
</CsOptions>
<CsInstruments>

  opcode FilSuf, S, So
  ;returns the suffix of a filename or path, optional in lower case 
Spath,ilow xin
ipos      strrindex Spath, "."
Suf       strsub    Spath, ipos+1
 if ilow != 0 then
Suf       strlower  Suf 
 endif
          xout      Suf
  endop

  instr suff
          prints    "Printing suffix:\n"
Suf       FilSuf    "/my/dir/my/file.WAV"
          puts      Suf, 1
Suf       FilSuf    "/my/dir/my/file.WAV", 1
          puts      Suf, 1
  endin
  
</CsInstruments>
<CsScore>
i "suff" 0 0
</CsScore>
</CsoundSynthesizer>

Credits

joachim heintz 2012


Previous Home Next
FilNam   StrayRev