yab | yet another Basic for HAIKU
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Finding your directory in yab

3 posters

Go down

Finding your directory in yab Empty Finding your directory in yab

Post by Admin Tue Apr 21, 2015 11:34 am

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 with the latest yab:

Code:

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

Admin
Admin

Posts : 7
Join date : 2015-04-19
Location : Coquille Oregon USA

https://yab-talk.board-directory.net

Back to top Go down

Finding your directory in yab Empty Re: Finding your directory in yab

Post by clasqm Tue Apr 21, 2015 12:42 pm

Code:
path$=attribute get$ "",""

is that two empty strings divided by a comma? Or is it a string containing "," - in which case why don't you have to escape the double-quotes?

Sorry, Jim, it just looks a little weird.
clasqm
clasqm

Posts : 5
Join date : 2015-04-21

Back to top Go down

Finding your directory in yab Empty Re: Finding your directory in yab

Post by Admin Tue Apr 21, 2015 12:59 pm

It is two empty strings, I have re-purposed the attribute get$ command to include this function. This requires the latest "bleeding edge" yab. I haven't made an .hpkg file yet.

Value$ = ATTRIBUTE GET$ Name$, Filename$
 Get the string value of the attribute Name$ for file Filename$.
Returns "true" or "false" for "Bool" type attributes.
If Name$="", returns a list of attribute names and their types separated
      by " | ". returns "Unsupported" for types that are not valid for yab.
If Name$ and Filename$ both = "", returns the current program directory.


This works with bound or un-bound apps, if the unbound app was double-clicked, or run from a terminal command.

Admin
Admin

Posts : 7
Join date : 2015-04-19
Location : Coquille Oregon USA

https://yab-talk.board-directory.net

Back to top Go down

Finding your directory in yab Empty Re: Finding your directory in yab

Post by clasqm Wed Apr 22, 2015 12:45 am

OK, I see where you are coming from now, thanks. You are using an otherwise unused option so that you don't need to create a whole new command. Great!
clasqm
clasqm

Posts : 5
Join date : 2015-04-21

Back to top Go down

Finding your directory in yab Empty Re: Finding your directory in yab

Post by bbjimmy Wed Apr 22, 2015 7:44 pm

I will probably add a separate Directory get$ command later. It will be an alias to this attribute get$ "","" command so that no changes will need to be made to programs using this one.
bbjimmy
bbjimmy

Posts : 10
Join date : 2015-04-21
Location : Coquille Oregon

http://fatelk.com

Back to top Go down

Finding your directory in yab Empty Re: Finding your directory in yab

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum