List names of sample files in my own directories

Hi all
feeling lazy today - I know how to print a list of samples in a folder, for Sonic Pi’s built in samples, using the sample_names function;

n = sample_groups.length #16

n.times do |i|  
  puts sample_groups[i]
  sleep 0.125
end

x = sample_names(:vinyl)

puts x

sample x.choose

can I also do this for my own samples please?

PD-Pi

You can use sample_paths for this - give it a folder (you can drag the folder into Sonic Pi to get the path) and it will return a ring of all samples in that folder. Look in the docs for more options (like you can limit it to samples with a particular string in the name).

3 Likes

thx so much @emlyn I can filter by string <3

Further to emlyn’s answer if youj just want the filenames without the path you can use this

slist= Dir.children "/Users/rbn/Desktop/samples/Chimes/"

puts slist.length
slist.each do
  puts slist[tick]
end

in teh example directgoryh gives output below

=>
 β”œβ”€ 13
 β”œβ”€ "chimes_c5.wav"
 β”œβ”€ "chimes_c4.wav"
 β”œβ”€ "chimes_c6.wav"
 β”œβ”€ "chimes_c3.wav"
 β”œβ”€ "chimes_a4.wav"
 β”œβ”€ "chimes_a5.wav"
 β”œβ”€ "chimes_fs3.wav"
 β”œβ”€ "chimes_ds3.wav"
 β”œβ”€ "chimes_fs4.wav"
 β”œβ”€ "chimes_a3.wav"
 β”œβ”€ "chimes_fs5.wav"
 β”œβ”€ "chimes_ds5.wav"
 β”œβ”€ "chimes_ds4.wav"

You can drag in the folder you want after slist=Dir.children

1 Like

Oooh, that’s handy Robin, thanks

(got a little blues scale going there?)