Check if a folder or file is selected?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
highend
Posts: 14946
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Check if a folder or file is selected?

Post by highend »

is report() a good / practical way to decide if the user has selected a directory or a file (or multiple files)?

If a directory is selected (e.g. "test.test1.test2") than

Code: Select all

 $SelectedItems = report("{Basename}?{Ext}|",1);
 msg SelectedItems;
displays: test.test1.test2?|

-> No extension (after the question mark) so I could test if the {Ext} is "" but my problem is that I sometimes have unix files with no extension, too and in this case the same check would result in "" for a file.

Is there a different / better way to do such a check?
One of my scripts helped you out? Please donate via Paypal

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Check if a folder or file is selected?

Post by Stefan »

You can use report() but not as you think since an folder name can contain dots too.

See some examples for IsFile and IsFolder:

Search for "Is it a file or an folder?" at > Scripting for beginners...
Search for "IsFolder / IsFile, check type of item" at > How did you start scripting?


- - -

EDIT + Upps! + sorry

report(basename) works only for FILES, not on folders.
Help wrote: {Basename}
· The field is set to the base name of the file (file name without extension).
· Folder names are returned unchanged.
Test:

Code: Select all

$SelectedItems = report("base:{Basename}     ext:{Ext}",1);
     msg $SelectedItems;

So your way can work too, but not for files with no extension as you have seen already.
So better use report(dir Y|N|D) or if exist()==n as you can see from my examples behind the links above.
.
Last edited by Stefan on 17 Jul 2011 13:01, edited 1 time in total.

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

Re: Check if a folder or file is selected?

Post by highend »

Thanks a lot Stefan.

I'll use

Code: Select all

$IsFile = report ("{Dir False|True|Drive}",1); 
  If ($IsFile=="True") {msg "It is a file"}else{ msg "no file"};
(and modify it for my script).
One of my scripts helped you out? Please donate via Paypal

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

Re: Check if a folder or file is selected?

Post by aliteralmind »

See

http://www.xyplorer.com/xyfc/viewtopic.php?f=5&t=13162

For alternative using SC 'exists'.
Windows 8.1, 64-bit

Post Reply