if (name_declared("pkgversions") != 4 ) {  execute("strdef pkgversions") }
sprint(pkgversions,"%sFileUtils = $Revision: 1.4 $, ",pkgversions)

begintemplate FileUtils
public basename, dirname, homedirname
public tempfilename, tempdirname

objref sf, f
strdef tmpstr

proc init() {
    sf = new StringFunctions()
}

proc basename() {
    pos = sf.head($s1,"/[^/]+$",tmpstr)
    tmpstr = $s1
    sf.right(tmpstr,pos+1)
    $s2 = tmpstr
}

proc dirname() {
    pos = sf.head($s1,"/[^/]+$",$s2)
}

proc tempfilename () {
    f = new File()
    f.mktemp()
    $s1 = f.getname()
}

proc tempdirname () {
    tempfilename(tmpstr)
    dirname(tmpstr,$s1)
}

proc homedirname () {
    system("echo  $HOME",tmpstr)
    sf.head(tmpstr,"\n",$s1)
}

endtemplate FileUtils