I am trying to pass in the file extension as a variable but it doesn’t seem to be working. when I run getlist.rb(txt)
def getlist(extension)
file = File.new("the_list.txt", "w")
Dir['../path/*.'+ extension].each { |f| file.puts File.basename(f, '.'+ extension).upcase }
end
Basically I want to drop in any file extension (txt, pdf, rb, etc) and it will give me the list without the extension names. Script works fine when it is hard coded just doesn’t work when I try to drop in a variable.
Best Regards,
AZCards
My example:
My main modifications:
getlist.rb(txt)– this only works, when txt is a variable, but I think you want ‘txt’)Update
Just in case you need a solution with multiple extensions and to call it from command line: