Files with no extension

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
Kucera
Posts: 108
Joined: 31 Mar 2008 01:37
Location: Canada
Contact:

Files with no extension

Post by Kucera »

Hello,
is there a way to filter for files with no extension? visual or selection, or via script?

I have a bunch of old (mostly text) files like that, and sometimes I would like to show only those in the list.
Then I would feel very lucky if I could actually, on double click, open them in Notepad, or rather, my favourite text editor TextPad. (so far selecting first in list, then clicking TextPad in Catalog works, but that means moving between the clicks (what a hardship, eh?)

Thanks for any advice
BTW, I just upgraded from ver.6.8 (licensed!) to v.9, impressed so much I bought a lifetime licence pro :)
Regards Emil

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

Re: Files with no extension

Post by TheQwerty »

Well first to filter with just files without extensions I believe this should work for you:

Code: Select all

!\|!.
That's filter out folders (!\) and anything with a period (!.). This would fail on files that are all extension (ie .htaccess), but if you really want those files as well it could be done through a regular expression.

Regarding double click to open check out the Portable Open with Menu (POM) and Portable File Associations (PFA), which can be defined under Tools->Customize File Associations..
If you click the Editor Mode button in that dialog you can just paste the following (and modify for your needs), which I'm using for TextPad:

Code: Select all

+"Open In Textpad" bat;ini;java;log;syn;tcl;txt;xml;xsl;xys>C:\Program Files\TextPad 5\TextPad.exe
+"Open In New Textpad" bat;ini;java;log;syn;tcl;txt;xml;xsl;xys>"C:\Program Files\TextPad 5\Textpad.exe" -m <items>

Kucera
Posts: 108
Joined: 31 Mar 2008 01:37
Location: Canada
Contact:

Re: Files with no extension

Post by Kucera »

Well first to filter with just files without extensions I believe this should work for you:

Code: Select all
!\|!.

That's filter out folders (!\) and anything with a period (!.). This would fail on files that are all extension (ie .htaccess), but if you really want those files as well it could be done through a regular expression.
Thank you very much, works like charm! Now of course I am curious about the regular expression, but I can certainly get my few .htaccess(es) manually. However :
Regarding double click to open check out the Portable Open with Menu (POM) and Portable File Associations (PFA), which can be defined under Tools->Customize File Associations..
If you click the Editor Mode button in that dialog you can just paste the following (and modify for your needs), which I'm using for TextPad:

Code: Select all
+"Open In Textpad" bat;ini;java;log;syn;tcl;txt;xml;xsl;xys>C:\Program Files\TextPad 5\TextPad.exe
+"Open In New Textpad" bat;ini;java;log;syn;tcl;txt;xml;xsl;xys>"C:\Program Files\TextPad 5\Textpad.exe" -m <items>
This still does not open the "no-extension file on the double click, though... Tried to include a ' ' and a "" with the extensions, as well as the !\|!. filter, but no dice. Do you have some more magic like the filter?
oh, and what is the difference between POM and PFA, if any?

Thanks and regards Emil

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

Re: Files with no extension

Post by TheQwerty »

Kucera wrote:Now of course I am curious about the regular expression
A couple of options:

Code: Select all

!\|>^\.?[^.]+$
Would exclude folders and show only files that contain zero periods, or one period if it's the first character. (ie, "file", ".htaccess", but not ".htaccess.bak")

Code: Select all

!\|>^\.|^[^.]+$
Would exclude folders and show either files that start with a period or do not contain a period. (ie, "file", ".htaccess", and ".htaccess.bak")

Kucera wrote:This still does not open the "no-extension file on the double click, though...
Oh right.. duh! Excuse my stupidity in not relating the two! :oops:
Hmm.. aside from defining a default for all files I don't think that's really possible right now.

Kucera wrote:oh, and what is the difference between POM and PFA, if any?
Well POM is really just a reference to the menu available via the "Open with" toolbar button or File->Open With..., and it is made up of entries from PFA.

Kucera
Posts: 108
Joined: 31 Mar 2008 01:37
Location: Canada
Contact:

Re: Files with no extension

Post by Kucera »

>curious about the regular expression
A couple of options:
Amazing! Can you recommend a good website that would teach me about regex's of the right kind to use with XY?
>still does not open the "no-extension file on the double click, though...
Hmm.. aside from defining a default for all files I don't think that's really possible right now.
How would I do that? May be worth trying; the office files and pdf's can always be opened from outside XY, don't have to be browsed to with a file manager so much.

Thanks and regards Emil

j_c_hallgren
XY Blog Master
Posts: 5826
Joined: 02 Jan 2006 19:34
Location: So. Chatham MA/Clearwater FL
Contact:

Re: Files with no extension

Post by j_c_hallgren »

Kucera wrote:Can you recommend a good website that would teach me about regex's of the right kind to use with XY?
There is a link on http://88.191.26.34/XYwiki/index.php/Re ... xpressions that might be useful...and on that wiki page itself are a few good hints.

And I suspect that http://en.wikipedia.org/wiki/Regex might be another good starting place to look...

(me admits to knowing not much about regex :oops: )
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.

Kucera
Posts: 108
Joined: 31 Mar 2008 01:37
Location: Canada
Contact:

Re: Files with no extension

Post by Kucera »

default for all files I don't think that's really possible right now.
>How would I do that?
Figured it out, very proud of myself :wink: ; all it needed was an asterisk instead of all those extensions. And the right-click menu still works for "open with" for all the other files, if I want to see them. I would still like to learn about the regular expression, mind you.
Thanks again! Regards Emil

Kucera
Posts: 108
Joined: 31 Mar 2008 01:37
Location: Canada
Contact:

Re: Files with no extension

Post by Kucera »

j_c_hallgren wrote:
Kucera wrote:Can you recommend a good website that would teach me about regex's of the right kind to use with XY?
There is a link on http://88.191.26.34/XYwiki/index.php/Re ... xpressions that might be useful.
Thanks, should have looked there first, of course. But you people are so generous withe your help that one gets spoiled a little.
Thanks and regards Emil

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

Re: Files with no extension

Post by TheQwerty »

Kucera wrote: Figured it out, very proud of myself :wink: ; all it needed was an asterisk instead of all those extensions. And the right-click menu still works for "open with" for all the other files, if I want to see them. I would still like to learn about the regular expression, mind you.
Good job!

For the regular expressions the wiki links to http://www.regular-expressions.info/ which is a great resource unfortunately it does cover some things outside of what's supported in XY. It really shouldn't be a problem as it's mostly some of the advanced topics and syntax.



Back on the open, my suggestion would have actually been much more complicated than just using * and requires scripting.
There's a ton of options here but the following might be easiest (know that yes the steps are simplistic but this is not a reflection of my opinion of anyone's abilities)..

1) In the main menu select User->Manage Commands... to open the Manage User-Defined Commands (UDC) dialog.
2) In the UDC dialog select 'Run Script' under Category.
3) Click New...
4) In the Caption field give this script a name such as "Open in TextPad as Default".
5) Click the Edit... button.
6) In the Edit Script dialog paste the following (changing the paths to TextPad for your system):

Code: Select all

"Open in TextPad as Default|C:\program files\TextPad 4\TextPad.exe"
	//Allow user to use System default instead of TextPad.
	if(Confirm("Open in TextPad?")) {
		//Open selected items in a single instance of TextPad.
		OpenWith("C:\program files\TextPad 4\TextPad.exe", "s");
	} else {
		//Misc.->File Operations->Open Selected Item(s) w/ OS Default
		#1053;
	}
7) OK out of Edit Script.
8) Click the button that says "#1400" to copy it to the clipboard, or remember this number. (The actual number shown could be different, but it will be in the 1400s.)
9) OK out of Manage UDCs.
10) Open the Customize PFA dialog (Tools->Customize File Associations...)
11) Add a new entry to the very end of the list with a value of (where 1400 is the value from step 8):

Code: Select all

"Open in TextPad as Default" *>::#1400;
12) OK out of Customize PFA.

Now when you double click a file that does not have another definition in PFA you'll get a prompt asking if you want to open it in TextPad or use the system default.
You could also create an entry before your new "*>..." one in PFA for any file types that you want to always use the system default and avoid the prompt using:

Code: Select all

"Open with System Association" {match pattern}>::#1053;

Kucera
Posts: 108
Joined: 31 Mar 2008 01:37
Location: Canada
Contact:

Re: Files with no extension

Post by Kucera »

Wonderful! both solutions work and both are useful, in different situations. But of course, I am still curious. In the script you suggested...
TheQwerty wrote: 6) In the Edit Script dialog paste the following (changing the paths to TextPad for your system):

Code: Select all

"Open in TextPad as Default|C:\program files\TextPad 4\TextPad.exe"
	//Allow user to use System default instead of TextPad.
	if(Confirm("Open in TextPad?")) {
		//Open selected items in a single instance of TextPad.
		OpenWith("C:\program files\TextPad 4\TextPad.exe", "s");
	} else {
		//Misc.->File Operations->Open Selected Item(s) w/ OS Default
		#1053;
	}
would it be possible to have the #1053; first, and if that returned a 'false', i.e., if there is no association (don't know if the scripting lingo allows it or if it would prevent the the Windows 'choose program' dialogue; am not brave enough to try too much), then carry on the 'open with TextPad' ? Avoiding the prompt that way?
Now when you double click a file that does not have another definition in PFA you'll get a prompt asking if you want to open it in TextPad or use the system default.
You know, give them an inch... :P

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

Re: Files with no extension

Post by TheQwerty »

Sorry for the delay, I got quite busy last week and as you'll see this request is no simple task...
Kucera wrote:would it be possible to have the #1053; first, and if that returned a 'false'
Strictly speaking - no, this isn't possible. The issue is #1053; has no return value, so there is no way to determine if it was successful or not.

Thankfully XY's scripting provides a function (GetInfo(RegCmd, extension)) which will take an extension and look up the associated program in the registry. This means it is possible to check for an associated program and if none is found open the item in Textpad, but it gets messy when it comes to handling selections of multiple items.

Furthermore, Open/OpenWith don't allow you to provide a ;-separated list of items, so the script either has to change the list selections for each open call, or it must open each item separately.

Thus I've attached two versions of the script that should work, however they have not been thoroughly tested. They are quite a mess but they get the job done; use at your own risk; blah blah blah. ;)



In each case the scripts takes the current selection and converts it to groups of items by extension and then opens each group.

In the first version ("UseDeafultApp"), each item in the group is opened separately and it will not make any changes to your list selections.

In the second ("UseDefaultApp (Selection")), each group of items is selected and then that group is opened. At the end it should reset the original selections.


There are two instances of the path to TextPad that you should change in both files (the first line and again near the end), and the prompt when opening multiple items is set to 12 but feel free to change that.


EDIT: Opps, forgot to attach the scripts. :oops:
To see the attached files, you need to log into the forum.

Kucera
Posts: 108
Joined: 31 Mar 2008 01:37
Location: Canada
Contact:

Re: Files with no extension

Post by Kucera »

TheQwerty wrote:Sorry for the delay, I got quite busy last week and as you'll see this request is no simple task...
You got to be kidding! I am amazed at the amount of work you have done, who needs an apology? But of course I still have to ask some questions:
TheQwerty wrote:In each case the scripts takes the current selection and converts it to groups of items by extension and then opens each group.
In the first version ("UseDeafultApp"), each item in the group is opened separately and it will not make any changes to your list selections.
In the second ("UseDefaultApp (Selection")), each group of items is selected and then that group is opened. At the end it should reset the original selections.
Not entirely sure what the difference is, but I really only craved to be able to double-click and get one file open, for which it works fine, as I followed your previous instructions and added the script to the Customize file associations (now as number 1401 :-) ).
Guess the 'multiple' open is done via Scripting-Load script file from the menu, or by putting the script.xys into the catalogue?
If you edify me on this, I should even be able to leave you alone for a while :D
Many many thanks,
regards Emil

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

Re: Files with no extension

Post by TheQwerty »

Kucera wrote:Guess the 'multiple' open is done via Scripting-Load script file from the menu, or by putting the script.xys into the catalogue?
Both of your guesses are correct, and there are even a few more ways.

If you have it working as a CFA on double click then it should work for multiple files when you trigger it via File->Open With, and similarly via the "Open With" toolbar button. It gets a little tricky though as they typically only show the program associated with the focused item (so if it matches another CFA that will show instead of this one).

You can also assign a customized keyboard shortcut (CKS) to the menu item or UDC, or create your own custom toolbar button (CTB) that will trigger the script.

Finally, if you have quick scripting enabled then anywhere you can enter an address and go to (address bar, go to dialog, etc) you could enter

Code: Select all

::Load("path_to_script");
If you place the script within the Scripts directory (Go->Go to Scripts Folder) then you can also omit the path and extension in that Load statement.



To better explain the difference..
In "UseDefaultApp.xys" the script gets a list of files and does a bunch of string parsing to eventually call Open or OpenWith on each and every item one at a time. This means if you have TextPad set to allow multiple instances it will open a new instance for each file. However, it also doesn't make any attempt to modify the selection in the list pane, so no matter what happens in the script your selection and the state of XY will not change.

In "UseDefaultApp (Selection).xys" the script uses string parsing only to group the items by extension. It then modifiers the list pane's selection to select each group and calls Open or OpenWith on the new selection. For example; if you selected "a.txt", "b.mp3", "c.txt" it would first group them by extension "a.txt;c.txt" and "b.mp3". Then it would select only "a.txt" and "b.txt" and call open or openwith. Then it would select only "b.mp3" and again call open or openWith. Thus with TextPad set to allow multiple instances this would open a single instance for each group (that would open in TextPad). In an attempt to make this less disruptive I do have it attempt to restore your original selection, but if the script exits before completion there's a chance your selection won't be the same as when you started the script.


For a single file you shouldn't see any difference between the two.

I feel the first is probably more reliable, but it will be more annoying when opening a lot of files that all run the same program.



Of course if Don changes Open/OpenWith to accept a ;-separated list of items instead of only a single item then the first version would become much better and have the same advantages as the second.

Kucera
Posts: 108
Joined: 31 Mar 2008 01:37
Location: Canada
Contact:

Re: Files with no extension

Post by Kucera »

For a single file you shouldn't see any difference between the two.
I feel the first is probably more reliable, but it will be more annoying when opening a lot of files that all run the same program.
Of course if Don changes Open/OpenWith to accept a ;-separated list of items instead of only a single item then the first version would become much better and have the same advantages as the second.
Right you are; it is strange to see all those TextPad windows one on top of the other, even though the TPad config does not allow multiple instances. However, this hardly comes into play, not much need for it. And just looking at all the stuff that you created shows how many ways to skin the cat there are in XY. Now I know what to start learning, if I ever find the energy to do that. But what I really need from the program, I now have, so thanks very much indeed.
Best regards Emil

Post Reply