yab | yet another Basic for HAIKU
Finding your directory in yab - Printable Version

+- yab | yet another Basic for HAIKU (https://yab.orgfree.com/forum)
+-- Forum: Programming in yab (https://yab.orgfree.com/forum/forumdisplay.php?fid=1)
+--- Forum: Snippets (https://yab.orgfree.com/forum/forumdisplay.php?fid=3)
+--- Thread: Finding your directory in yab (/showthread.php?tid=2)



Finding your directory in yab - bbjimmy - 06-07-2015

The old way:

Code:
//////////////////////////////////////////////////////////////////
sub getdir$( programname$)
// find out in which directory we are in
////////////////////////////////////////////////////////////////
local path$
local catch
catch=0
if (!peek("isbound")) then
   path$=system$("ps")
   x=instr(path$,"/"+programname$)
   path$=left$(path$,x)
   for x=len(path$)-1 to 1 step -1
      if (instr(path$," ",x) and catch=0) catch=x+1
   next
   path$=right$(path$,len(path$)-catch)
   path$=trim$(path$)
   if path$="/" then
        path$ = trim$(system$("pwd"))+"/"
   else
      path$="/"+path$
   endif

else
path$=trim$(peek$("directory") )
path$=path$+"/"

end if

return path$
end sub


The new way:


Code:
//////////////////////////////////////////////////////////////////
sub path$()
// find out in which directory we are in
////////////////////////////////////////////////////////////////
path$=attribute get$ "",""
path$=path$+"/"
return path$
end sub


This uses attribute get$ with no attribute name and no file name.


Free Web Hosting