Page 1 of 1
Determining if curpath or curitem is the "root" directory
Posted: 08 Aug 2014 03:10
by klownboy
Hi, I was wondering if there is a simpler or more elegant way to determine if the <curpath> when the tree has focus, or <curitem> when the list has focus, is the "root" directory of any drive. What I'm currently doing is using substr on the <curitem> and <curpath> like this...
Code: Select all
if(get("FocusedControl",) == "T") { // when tree has focus
if(substr("<curpath>", -1) == ":") {$root_warning = "1";}
if(get("FocusedControl",) == "L") { // when list has focus
if(substr("<curitem>", -2, 1) == ":") {$root_warning = "1";}
The input could be from the tree or List. It would be even better if the method worked regardless of focus. <curpath> when the tree has focus, the root drive is never back-slashed whereas, <curitem> when the list has focus, the root drive is back-slashed. Might there be a better way that I'm not aware of or stumbled across?
Thanks,
Ken
Re: Determining if curpath or curitem is the "root" director
Posted: 08 Aug 2014 07:53
by Stefan
Don't know if more elegant, but maybe better readable:
Code: Select all
if("<curitem>" != ""){$path = "<curitem>";}else{$path = "<curpath>";}
if(strlen($path) < 4){$root_warning = 1;}
if($root_warning == 1){echo "root!!! $path";}else{echo "All right, $path";}
Re: Determining if curpath or curitem is the "root" director
Posted: 08 Aug 2014 12:42
by klownboy
Thanks Stefan, that is a better approach especially since I can use it for either case of Tree or List having focus unless someone out there has double alphabet drive letters.

I left out part of the script, so as not to confuse things, where I establish the <curitem>
or <curpath> (depending on the focus) as a variable $cur_folder. So l can simply use strlen on $cur_folder.
Code: Select all
if(strlen($cur_folder) < 4){$root_warning = 1;}
It's also is a better method for determining whether if the user has selected a folder in the tree or list since <curitem> will always be "" when the Tree has focus rather than the more lengthy "get FocusedControl" statements.
Thanks again,
Ken
Re: Determining if curpath or curitem is the "root" director
Posted: 16 Aug 2014 13:01
by klownboy
To follow-up strickly to get things right for history...someone looks at this 4 years from now. I'm not so sure if I was clear in the post or title "determining if the curpath or curitem is the root directory", that I was looking for a folder "only". Within a day of the last post I did determine that the first line here
Code: Select all
if("<curitem>" != ""){$path = "<curitem>";}else{$path = "<curpath>";}
if(strlen($path) < 4){$root_warning = 1;}
will fail if you select a "file" in the list and then click into the tree the "curitem" is still valid and would be used which is obviously not what I wanted. A simple change fixed that, to make sure the "curitem" is a folder.
Code: Select all
if(("<curitem>" != "") AND (exists("<curitem>") != "1")) {$cur_folder = "<curitem>";} else {$cur_folder = "<curpath>";}
Thanks