Function/Command for Finding Index Value of Currently Selected File

I'm hoping someone can help me with this.

Let's say I have a folder that contains the following files:
a.txt
b.txt
h.txt
t.txt
u.txt
x.txt
z.txt

I'm trying to make a button that would bring up a dialog asking for two different filenames, find the index values of each of those files, then select the range of files between those two indexes.

For example:
File Name 1: h.txt -> index value is "3" -> Store index value as variable "indexFile1"
File Name 2: x.txt -> index value is "6" -> Store index value as variable "indexFile2"

Select RANGE indexFile1 - indexFile2

So the selection would look like this:
a.txt
b.txt
h.txt
t.txt
u.txt
x.txt
z.txt

Is there a function/command that can grab the index value of a selected file and store it as a variable? And is it even possible to use the Select RANGE function with variables like I described above?

You might not need extra commands for this.

If you want to select everything between two files, based on their names, you can simple click the first and shift+click the second.

Alternatively, if you want to do it based on their positions, you can (optionally) turn on the Index column (so you can see what their positions are) and then type something like #3-6 into the file display to select files 3 through 6.

I was mostly hoping for an index-based solution because, while the example I described was a folder with only 7 files in it, my real-life work situation involves a folder filled with hundreds of files, and selecting 80 to 90 of them by manually clicking, or by turning on the index column and scrolling down to find the indexes of the two files isn't very time-efficient.

Is there a way to automate this with functions like I described above?

You could certainly do it your way using scripting, since scripts can get the file list, and ask for two filenames to be typed in.

I am afraid, even a script has no access to this column.

You could use the filter bar to quickly navigate to the two index files, select them, and then use this script to select the files in between:

The index column, at least in general, is just a count from the first file to the last, so a script should be able to work out the index for an item by iterating through the list of items.