Skip to content

Instantly share code, notes, and snippets.

@kevbuchanan
Last active December 17, 2015 03:38
Show Gist options
  • Save kevbuchanan/5544194 to your computer and use it in GitHub Desktop.
Save kevbuchanan/5544194 to your computer and use it in GitHub Desktop.
From Pine's Learn to Program. This program creates a music playlist in the specified directory.
directory = '/Users/kevinbuchanan/Music'
Dir.chdir directory
playlist = {}
while true
puts 'Enter a song name to add to the playlist: (Press enter when done)'
song = gets.chomp
if song != ''
file = Dir.glob("**/*#{song}*.???")
if !file.empty?
playlist[song] = file
puts "#{song} was added to the playlist."
else
puts "#{song} was not found."
end
else
break
end
end
puts "What would you like to title the playlist? (No Spaces)"
title = gets.chomp
File.open "#{title}.m3u", 'w' do |f|
playlist.values.flatten.each {|song| f.write song + "\n"}
end
puts "Your playlist has been created here: #{directory}"
@kevbuchanan
Copy link
Author

This actually returns all songs containing the word that is entered when searching. I need to figure out how to return only exact matches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment