How to load random audio files in Supercollider ?

I’m looking for a way to load several audio files into SC buffers randomly selected from a given directory on my computer.

Let’s say I’ll have 20 buffers I’m gonna work with in SC, I want to fill them with 20 different wav audio files with a single function.

How would you do that in Super Collider?

Is there a way to do this directly in SuperCollider? Or should I create an external program/script that would create a JSON containing all the paths (something similar to the jar maps used in programs like Reaktor ?) and use that in SC ?

That’s just an idea, I don’t even know if that’s possible, I’ve seen many tutorials on sound synthesis in SC, but not many about sound files and file management…

What’s the best approach ?


Not near a computer at the moment but I believe you could use the PathName object and its .files method:“myFolder”).files.scramble.copyFromStart(20)


Yes, it’s working! It fills up an array with 20 paths and filenames. That’s exactly what I was looking for. Thank you very much @duckpow

I’ll have a closer look at all these methods, loads of interesting possibilities. Perhaps there’s a way even to make it recursive when there are a lot of sub-folders, or to add selection filters. I’ll dive in the documentation and report here if I find something.
Thanks again ! :slight_smile:

v ="/Users/Shared/Lone Forest Library/Samples/Drums/Kick").files.scramble.copyFromStart(20);

To make it recursive, I simply added an asterisk after the parent folder.
I was about to try using a “for loop” with the list of folders but this works just fine.

e ="/Users/Shared/Lone Forest Library/Samples/Drums/*").files.scramble.copyFromStart(20);