Force to load soundfiles in a certain order?

Hi everyone. I try to use PlayBuf to read semi-randomly some soundfiles, but the program randomly allocates numbers to the files according to the order in which it loads them into the buffers (there is 53 soundfiles).
Is there any way to force it to load them into the buffer in the order they appear in my folder (here named /voix)?

~voix = “voix/*.wav.”.resolveRelative.pathMatch.collect({
arg path;, path);

~poeme1 ={\playerPoly, [
\buf, [~voix[4],~voix[15],~voix[21],~voix[37],~voix[38]].choose,
\amp, 0.3,

The catch here is that there might not be an intrinsic order in the filesystem. It’s very likely that your system’s file browser is sorting the filenames according to one set of rules, while pathMatch is sorting by different rules. (A plain ASCII string comparison considers "5-a" > "25-a" while a comparison that takes leading numbers into account would see "5-a" < "25-a".)

If order matters, then it makes sense to create filenames where the sort order is unambiguous. An easy way is a numeric prefix with leading zeros: 00-abc, 01-def etc. Then a numeric-aware and plain ASCII would get the same result. This is easier than trying to write a fancier string comparator.


Thank you so much! I renamed the files with 00-, 01-, 02- as prefix and it’s working. :hugs: