Get selected full path w/o two pathcomponents?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
aliteralmind
Posts: 261
Joined: 02 Dec 2014 16:49

Get selected full path w/o two pathcomponents?

Post by aliteralmind »

Code: Select all

:: echo getpathcomponent(, "path").'\'.getpathcomponent(, "file");
Is there an alternative way of getting the full path of the selected item?
Windows 8.1, 64-bit

highend
Posts: 14950
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Get selected full path w/o two pathcomponents?

Post by highend »

Code: Select all

::echo "<curitem>";
One of my scripts helped you out? Please donate via Paypal

Filehero
Posts: 2731
Joined: 27 Feb 2012 18:50
Location: Windows 11@100%

Re: Get selected full path w/o two pathcomponents?

Post by Filehero »

Code: Select all

::echo <curitem>;
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. :mrgreen:
Last edited by Filehero on 08 Jan 2015 18:12, edited 2 times in total.

aliteralmind
Posts: 261
Joined: 02 Dec 2014 16:49

Re: Get selected full path w/o two pathcomponents?

Post by aliteralmind »

Thanks. Only using a single file in this case.
Windows 8.1, 64-bit

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Get selected full path w/o two pathcomponents?

Post 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.

aliteralmind
Posts: 261
Joined: 02 Dec 2014 16:49

Re: Get selected full path w/o two pathcomponents?

Post 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>
Windows 8.1, 64-bit

aliteralmind
Posts: 261
Joined: 02 Dec 2014 16:49

Re: Get selected full path w/o two pathcomponents?

Post by aliteralmind »

A related question:

If the extension

Code: Select all

::echo getpathcomponent(, "ext");
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?
Windows 8.1, 64-bit

aliteralmind
Posts: 261
Joined: 02 Dec 2014 16:49

Re: Get selected full path w/o two pathcomponents?

Post 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"};
Windows 8.1, 64-bit

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Get selected full path w/o two pathcomponents?

Post 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.

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Get selected full path w/o two pathcomponents?

Post 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) :wink:)

edit: whoa, you two prevented me from posting three times in succession with your rapid fire replies! :kidding:
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

aliteralmind
Posts: 261
Joined: 02 Dec 2014 16:49

Re: Get selected full path w/o two pathcomponents?

Post by aliteralmind »

Got it!

Code: Select all

$isDir = (exists($origPath) == 2);
if($isDir)  {
   echo "dir!";
}
P.S. I love ternarys! :) I come from Java.
Windows 8.1, 64-bit

Post Reply