I have a directory with files named like:
- snare-2.wav
- snare-3.wav
- snare.wav
I think the files are in that order because that’s how naïve sorting works (the - sorts before .) so that’s the order that Lilt’s dir[] built-in returns them.
I would like to process them according to the obvious order:
- snare
- snare-2
- snare-3
…so I think I need to do two things: trim the last four characters off the filename, and sort by the result.
My first attempt was:
select basename:(-4 drop name)
where type=".wav"
orderby basename asc
from dir["samples"]
…but this doesn’t work. For starters, -4 drop name drops the last 4 item from the name column, not the last 4 characters of each value in the column.
My first attempt was to try -4 drop @ name to “push” the drop deeper into the array, in the same way that sum @ items sums each item individually. Unfortunately, Lil doesn’t seem to understand that syntax, and the docs suggest it should only work for unary operators like sum, not binary operators like drop.
My second attempt was to do the dropping inside a loop:
each r in rows select name
where type=".wav"
from dir["samples"]
-4 drop r.name
end
…but then I went to figure out how to sort the resulting list, and it seems like there’s no way to sort lists, only tables? So this seems to do what I want:
select
orderby name asc
from table (list "name") dict list
each r in rows
select name
where type=".wav"
from dir["samples"]
-4 drop r.name
end
…but that seems like a mess. Surely there’s a better way?