Page 1 of 1
Get selected full path w/o two pathcomponents?
Posted: 08 Jan 2015 17:38
by aliteralmind
Code: Select all
:: echo getpathcomponent(, "path").'\'.getpathcomponent(, "file");
Is there an alternative way of getting the full path of the selected item?
Re: Get selected full path w/o two pathcomponents?
Posted: 08 Jan 2015 17:45
by highend
Re: Get selected full path w/o two pathcomponents?
Posted: 08 Jan 2015 17:48
by Filehero
For multiple selections
get is the key.
Code: Select all
:: echo get("SelectedItemsPathNames", "|", "a");
it's true, I'm always too late to the party.

Re: Get selected full path w/o two pathcomponents?
Posted: 08 Jan 2015 17:48
by aliteralmind
Thanks. Only using a single file in this case.
Re: Get selected full path w/o two pathcomponents?
Posted: 08 Jan 2015 18:06
by TheQwerty
aliteralmind wrote:Thanks. Only using a single file in this case.
Then also note that
<curitem> only returns the currently selected AND focused item.
If you want the focused item regardless of selection, use
<focitem>.
If you want the selected item(s) regardless of focus, use
<get SelectedItemsPathNames> or
Get('SelectedItemsPathNames') as Filehero suggested.
Re: Get selected full path w/o two pathcomponents?
Posted: 08 Jan 2015 18:10
by aliteralmind
Actually, it turns out I want the behavior of the original code, then:
Code: Select all
:: echo getpathcomponent(, "path").'\'.getpathcomponent(, "file");
If nothing is selected, then I want the directory. Would be nice to have <fo**D**item>
Re: Get selected full path w/o two pathcomponents?
Posted: 08 Jan 2015 18:18
by aliteralmind
A related question:
If the extension
is the empty string, then it's a folder (or a no-extension file...). Is there a more reliable way to detect if it's a folder?
Re: Get selected full path w/o two pathcomponents?
Posted: 08 Jan 2015 18:21
by aliteralmind
Got it:
http://www.xyplorer.com/xyfc/viewtopic. ... 755#p61935
From highend:
Code: Select all
$IsFile = report ("{Dir False|True|Drive}",1);
If ($IsFile=="True") {msg "It is a file"}else{ msg "no file"};
Re: Get selected full path w/o two pathcomponents?
Posted: 08 Jan 2015 18:24
by TheQwerty
The Exists SC is probably a better method now.
GetPathComponent is not aware of what type of object the path is, so a folder containing a period is treated like a file with extension.
Re: Get selected full path w/o two pathcomponents?
Posted: 08 Jan 2015 18:24
by bdeshi
aliteralmind wrote:Thanks. Only using a single file in this case.
aliteralmind wrote:If nothing is selected, then I want the directory.
Code: Select all
:: echo (<selitems> =='')?<curpath>:getpathcomponent(, "file");
Returns current path if nothing selected, else returns selected (and focused) item's full path.
(btw, Minified If-else block. (help->scripting->ternary conditional)

)
edit: whoa, you two prevented me from posting three times in succession with your rapid fire replies!

Re: Get selected full path w/o two pathcomponents?
Posted: 08 Jan 2015 18:38
by aliteralmind
Got it!
Code: Select all
$isDir = (exists($origPath) == 2);
if($isDir) {
echo "dir!";
}
P.S. I love ternarys!

I come from Java.