Page 1 of 1

Select every x'th line (and more)

Posted: 25 Nov 2008 23:59
by Pagat
Hi there,

:arrow: Download Select.xys At least XY v7.90.0030 is required.

so, earlier today i read a thread from Stefan where he asks for the possibility to select every second line and stuff like that. I was pretty sure it's possible via Scripting and so i got hooked and wrote the following little script.

As of now the following scenarios are possible:
  • You can either enter the line number where to start the new selection or use the current selection as starting point.
  • You can choose if all of the following items or only every 2nd, 3rd, 4th, ... item will be selected
  • You can choose a maximum number of items. E.g.: select every 3rd item for the next 100 items (or go till the end of the list)
  • It's possible to create "presets" which can be loaded via nicknames/aliases (Did i mention that i love nicknames ;) ). Therefore you only need to type in "youralias" to load a preset which will for example select every 2nd item in the next 100 items.
    For this, an INI file "Select.ini" (to be more exact: [basename of the scriptfile].ini is created in the same directory as the xys file. This ini file will also be used to store the last used values.
The actual selection takes place in two steps. First, every x'th item is selected on its own. The name of the item is appended to the "itemlist". After the script went through, this list is used for the selfilter command to select all of the items.

Known disadvantages:
  • For many items the script needs a little time to go through the list one by one.
  • The scrolling position is not preserved.

EDIT: I almost forgot: To save a "preset" you need to edit the INI file and add sections which look like the following:

Code: Select all

[first10]
Index=1
Offset=1
Length=10
Where "first10" is the name of that preset, Index is the starting line, Offset=1 means that every following item is selected, Length=10 means that the script stops after 10 items.

The name of the preset can be entered in the first input box ("Line number to start from").

:arrow: Update 09.01.2009

Code: Select all

/*	Select

	v0.01.0006	2009.01.09	XY v7.90.0030	CJ v0.01.0002
		+ Added changelog view through common-jacky library. To show the changelog
			call the script with label '_AutoChangelog'

	v0.01.0005	2009.01.06	XY v7.90.0030	CJ v0.01.0001
		+ Made sure recursion checker is disabled via 'setting' command
		+ Added automatic update support for the script through jacky's XYAU. To
			install the script in XYAU call the script with label '_InstallInXYAU'

	v0.01.0004	2008.12.01	XY v7.80.0030
		! Wrong results when seIecting 'next' 5 files... Fixed.

	v0.01.0003	2008.10.26	XY v7.80.0030
		! If 0 was entered as index (starting point) the script did nothing. Now 0
			is replaced by 1
		! The script now stops after x seIected items. Before, the skipped items
			were also counted

	v0.01.0002	2008.10.26	XY v7.80.0030
		! A length of 0 was incorrectly replaced by 1. Now it's replaced by the
			total number of items in the list

	v0.01.0001	2008.11.25	XY v7.80.0030
		+ first release
*/
Download Select.xys At least XY v7.90.0030 is required.

Re: Select every x'th line (and more)

Posted: 26 Nov 2008 00:16
by jacky
Very nice stuff, well done. Haven't had time to play with it yet, but instead of using a VF why don't you simply select the files directly (Selection Filter) ?

Code: Select all

  // instead of this:
  filter $itemlist;
  sel a;
  filter;

  // just do this:
  selfilter $itemlist;
Should select all your items without the need to use/change any VF ;)

Re: Select every x'th line (and more)

Posted: 26 Nov 2008 00:37
by Pagat
d'oh! i totally forgot about selfilter :)

I updated the script, thanks... I guess the next thing you tell me is, that there is a built in command for those 83 lines of code :D

Re: Select every x'th line (and more)

Posted: 26 Nov 2008 09:57
by Stefan
Hi Pagat,
thank you for your script. I think i can learn a lot from it.

Here my experiences:
(i hope i recall all correctly)

- First the script didn't work. I think i saw the jump through the lines, but nothing was selected.

- Then i enable 'Step through scripts' .... then then script select some files correctly.
(or it was that i have to set the focus on an file first? maybe this)

- Then i disable 'Step through scripts' .... but then the "Scripting Error" box appears:

The current script appears to be recursive.
The stack depth is 3.

- I click 'Continue' twice .... then the script worked and some files are selected as it should be.

But this has nothing to do with your script, this 'Step through scripts' appears for an other script (with 'Try script') too,
even i had enabled and disabled this 'Step through scripts' -option in the meantime.

(i have now restartet XY, but this "Scripting Error" box still appears everytime)


----

Then i see an glitch:
If i use 0 for 'Stop after x items' the script does nothing, i mean I see nothing happens, even not the "Scripting Error" box
If i use f.ex. '99' (more files then i have in the list) for 'Stop after x items' ........... then it's working.

And BTW, no push ;-) but this 'Stop after x items' should count selected files instead of all files in list.
I mean: start at '0', Step '2', Stop after 'x' files selected.
Otherwise the user have to count himself: every third file, i need 8 files, that are 3x8 items, so stop after 24 items (well, or like that)

Over all this is an very usefull script right now nevertheless, many thanks pagat.



Pagat wrote:.. I guess the next thing you tell me is, that there is a built in command
I would like to see this feature build-in, because this little extras make the different between FileManagers.

Re: Select every x'th line (and more)

Posted: 26 Nov 2008 10:29
by Pagat
"Try Script" always starts with stepping enabled. Regarding the recursion-warning: You need to turn the recursion checker off since the script uses recursion on purpose: http://88.191.26.34/XYwiki/index.php/IN ... hecker_Off

"0" as length: you are right, "0" was incorrectly corrected to "1". I changed the script so that "0" is now replaced by the total number of items in the list.

I'll take a look at the other things you mentioned in the evening when i have a little more time :)

Re: Select every x'th line (and more)

Posted: 26 Nov 2008 16:32
by Stefan
Pagat wrote:"Try Script" always starts with stepping enabled. Regarding the recursion-warning: You need to turn the recursion checker off since the script uses recursion on purpose: http://88.191.26.34/XYwiki/index.php/IN ... hecker_Off
Thanks:
Wiki wrote:Switch Recursion Checker Off
When writing your scripts, you might want to have one script call itself (using command load or sub).
Of course, if you don't take care, you could end up in an infinite loop which would result in some problems...
Trying to prevent such an issue, XY comes with a recursion checker that will pop up a warning message
when a recursion is spotted and gives you the opportunity to cancel the script execution.

If you do not want these warnings and are confident that you won't create an endless loop,
you can switch off the recursion checker by setting this entry to a value of 1 :

[Settings]
ScriptRecursionWarningOff=0
WOW, what an great feature :thumpsup: (i wish i had this for VBS/VBA files too :lol:
But shouldn't this feature not better be script-wise? I mean as first line in an script as "directive" like #ScriptRecursionWarningOff
Because i turn it now off "global" because i want to use Pagats script, and later i script myself and would need this feature enabled.

-

Pagat kindly wrote: "0" as length: you are right, "0" was incorrectly corrected to "1". I changed the script so that "0" is now replaced by the total number of items in the list.

I'll take a look at the other things you mentioned in the evening when i have a little more time :)
Thanks :D

Re: Select every x'th line (and more)

Posted: 26 Nov 2008 22:17
by Pagat
So i changed the following things:

A length of "0" is now correctly changed to the max number of items in the list (as mentioned above)

If "0" was entered as index but no file was actually selected then the script did nothing. It now defaults to the first item under such circumstances.

"Stop after 'x' selected items" (renamed the input box): does now what it says. No calculations required :)

If you turned off the recursion checker and execute the script outside of "Try script" all of the mentioned problems should be solved...

Re: Select every x'th line (and more)

Posted: 26 Nov 2008 22:28
by admin
Stefan wrote:WOW, what an great feature :thumpsup: (i wish i had this for VBS/VBA files too :lol:
But shouldn't this feature not better be script-wise? I mean as first line in an script as "directive" like #ScriptRecursionWarningOff
Because i turn it now off "global" because i want to use Pagats script, and later i script myself and would need this feature enabled.
Makes sense to me. But lets hear jacky... :)

Re: Select every x'th line (and more)

Posted: 26 Nov 2008 22:45
by Pagat
admin wrote:Makes sense to me. But lets hear jacky... :)
I was about to say the same thing. And i thought that jacky already discussed that with you but i guess i was wrong 8)

Re: Select every x'th line (and more)

Posted: 26 Nov 2008 23:00
by jacky
admin wrote:
Stefan wrote:WOW, what an great feature :thumpsup: (i wish i had this for VBS/VBA files too :lol:
But shouldn't this feature not better be script-wise? I mean as first line in an script as "directive" like #ScriptRecursionWarningOff
Because i turn it now off "global" because i want to use Pagats script, and later i script myself and would need this feature enabled.
Makes sense to me. But lets hear jacky... :)
Well, I understand the idea, I would agree with it, I also thought of asking to have it added to setting(p) in the past but I'm not sure it's a good idea. Because it can also be seen as a security measure, at least as long as things such as loops aren't "natively" supported by XY... Then it should definitely added to setting(p) for sure.

On the other hand now that we do have ternary, loops are pretty much officially supported, so it might make sense, yes. Okay I vote yes. (One can always read scripts/use stepping mode to be secure...)

Re: Select every x'th line (and more)

Posted: 01 Dec 2008 09:43
by Pagat
Although i do not use the script in my everyday work, i polished it a little bit because i was not satisfied with the result under some circumstances. (For example selecting "next 5 files" produced some glitches with the focused/selected file(s) and one item between the last and the next items was missing).

The new input boxes are used now, therefore XY v7.80.0030 is necessary to use the script.

Re: Select every x'th line (and more)

Posted: 09 Jan 2009 21:24
by Pagat
I actually had use for this script a few days ago when i saw no apparent possibility to select every second file (some kind of preview files, each for one 'real' file) because there was no system in the naming scheme. I made a few small updates to the script, mainly for myself to be able to use jackys XYAU for that script. Here's the changelog:

Code: Select all

/*	Select

	v0.01.0006	2009.01.09	XY v7.90.0030	CJ v0.01.0002
		+ Added changelog view through common-jacky library. To show the changelog
			call the script with label '_AutoChangelog'

	v0.01.0005	2009.01.06	XY v7.90.0030	CJ v0.01.0001
		+ Made sure recursion checker is disabled via 'setting' command
		+ Added automatic update support for the script through jacky's XYAU. To
			install the script in XYAU call the script with label '_InstallInXYAU'

	v0.01.0004	2008.12.01	XY v7.80.0030
		! Wrong results when seIecting 'next' 5 files... Fixed.

	v0.01.0003	2008.10.26	XY v7.80.0030
		! If 0 was entered as index (starting point) the script did nothing. Now 0
			is replaced by 1
		! The script now stops after x seIected items. Before, the skipped items
			were also counted

	v0.01.0002	2008.10.26	XY v7.80.0030
		! A length of 0 was incorrectly replaced by 1. Now it's replaced by the
			total number of items in the list

	v0.01.0001	2008.11.25	XY v7.80.0030
		+ first release
*/
Download Select.xys At least XY v7.90.0030 is required.

Re: Select every x'th line (and more)

Posted: 06 Aug 2010 15:43
by SkyFrontier
Crashes XY 9.40.0003 at the 449th item (selecting mainly .zip files).
Works fine for text files and folders. FWIW.

EDIT:: Splitting into chunks of < 400 files did the trick (values: 0, 1, 399 - you'll know what those numbers are when using the script! :wink: ).

Re: Select every x'th line (and more)

Posted: 06 Aug 2010 15:56
by SkyFrontier
I'd bet this is an XY limitation rather than the script itself. Some times the selection appears slowly on the screen, disregarding size of files, going back to normal after a few seconds. The crash occurs after a bit longer freeze at the 449th file. Leave this for our beloved Admin's meditation.
-Anyway, easier and faster than manual selection I've ever seen this far!!! XY rocks! 8)