I am trying to make a small change to a Ruby script so i can specify a folder location at runtime.
I was pretty sure that this would be an easy task, even though i am not a Ruby programmer, but i cannot find the correct syntax.
puts "Enter folder name and press enter: "
folder = gets
files = Dir.glob("folder/[0-100]*.txt"); # What is the correct syntax to use, so the content of the variable folder will be used?
puts files
To insert a variable (or any ruby expression) into a string, you can use
#{}:Also note that the string returned by
getswill have a newline (\n) at the end, which isn’t valid in folder names of course. So you’ll have to use thechompmethod to get rid of that.