Finding your directory in yab
3 posters
Page 1 of 1
Finding your directory in yab
The old way:
The new way with the latest yab:
- 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
Re: Finding your directory in yab
- 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- Posts : 5
Join date : 2015-04-21
Re: Finding your directory in yab
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.
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.
Re: Finding your directory in yab
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- Posts : 5
Join date : 2015-04-21
Re: Finding your directory in yab
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.
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|