Page 1 of 1

Check if a folder or file is selected?

Posted: 17 Jul 2011 11:08
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?

Re: Check if a folder or file is selected?

Posted: 17 Jul 2011 12:49
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.
.

Re: Check if a folder or file is selected?

Posted: 17 Jul 2011 13:01
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).

Re: Check if a folder or file is selected?

Posted: 08 Jan 2015 18:42
by aliteralmind
See

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

For alternative using SC 'exists'.