Cant seem to find whats worng

Could anybody help me to figure out what is wrong with this script. I am
new to ruby and this script is supposed to make a playlist, which it
does do, but when I try to use the playlist it is empty. Thanks.

def shuffle(arr)
shuf = []

while arr.length > 0
rand_sel = rand(arr.length)

curr_sel = 0
new_arr = []

arr.each do |x|
  if curr_sel == rand_sel
    shuf.push(x)
  else
    new_arr.push(x)
  end

  curr_sel = curr_sel + 1
end

arr = new_arr

end

shuf
end

songs = shuffle(Dir[’ **/*.mp3’])

File.open “dat playlist.m3u”, “w” do |x|
songs.each do |mp3|
x.write mp3 + “\n”
end
end

puts “Das it mane. Das it”

Hi,

Nuggety N. wrote in post #1081961:

Could anybody help me to figure out what is wrong with this script. I am
new to ruby and this script is supposed to make a playlist, which it
does do, but when I try to use the playlist it is empty. Thanks.

A more meaningful thread title would have been nice…

So you have checked that the playlist file contains the correct entries?
And still it appears to be empty when you open it with your music
player? What happens when you write a playlist “by hand”?

I’m not sure, but this doesn’t look like a Ruby problem. If the file
paths are there, then your Ruby script has done exactly what it should
do. Everything else is up to your music player.

By the way, the “shuffle” method is useless. The Array class already has
a shuffle method built in:

Sorry about the title. No the playlist file does not contain any data,
and is 0 bytes. When I import playlist into itunes it is just as though
I had just selected create a new playlist and it was awaiting song sto
be added. As for the method it is from a task from a learn to program
book so I can’t really say why it wanted a new method to be created.
Thanks.

Nuggety N. wrote in post #1081976:

Sorry about the title. No the playlist file does not contain any data,
and is 0 bytes.

I see. In this case the songs array must be empty. Try to remove the
whitespace before the " **/.mp3" and make sure you’re in the right
directory. That is, check the result of Dir[’ **/
.mp3’] before anything
else.

Jan E. wrote in post #1082004:

I see. In this case the songs array must be empty. Try to remove the
whitespace before the " **/.mp3" and make sure you’re in the right
directory. That is, check the result of Dir[’ **/
.mp3’] before anything
else.

Ok thanks, I’ll do that and let you know how it goes.

Nuggety N. wrote in post #1082007:

P.S I forgot to mention this before, but I am doing this for a research
project folio, and was wondering if you would mind me using this thread
in it?

No problem.

Nuggety N. wrote in post #1082005:

Jan E. wrote in post #1082004:

I see. In this case the songs array must be empty. Try to remove the
whitespace before the " **/.mp3" and make sure you’re in the right
directory. That is, check the result of Dir[’ **/
.mp3’] before anything
else.

Ok thanks, I’ll do that and let you know how it goes.

Yeah, works well now, thanks heaps for that.
P.S I forgot to mention this before, but I am doing this for a research
project folio, and was wondering if you would mind me using this thread
in it?

Cheers.