From: Robert Klemme Date: 2010-03-13T18:55:07+09:00 Subject: Re: Dir.glob problem On 03/13/2010 01:40 AM, Michael W Ryder wrote: > Michael W Ryder wrote: >> David Vlad wrote: >>> In the program Im making I need to read some wma files into a variable >>> and I did like this: >>> >>> songs = Dir.glob("C:\\Users\\Public\\Music\\Sample Music\\*.wma") >>> >>> Note that this is NOT the wrong directory, I've copy pasted it from the >>> map itself and also the files are wma and nothing else. My programming >>> teacher has no idea why this dosnt work and the other ppl I've talked >>> with dosnt know either. Most said something like "aside from a simple >>> mistake like wrong directory/extension, I don't know what could be going >>> wrong." So now this forum is my last resort, why on earth dosnt this >>> work?! >> >> The only way I could get it to work is to use the example at >> http://ruby-doc.org/core/classes/Dir.html and create a directory >> variable such as: lfiles=Files.join("C:", "Users", "Public", "Music", >> "Sample Music", "*.wma") and then use a=Dir.glob(lfiles). >> The only problem with that approach is that the entire path is added >> to each file. I don't know if this is a concern or not. > > Further experimenting found two other solutions. The first is to use: > a=Dir.glob("C:/Users/Public/Music/Sample Music/*.wma") which has the > same "problem" as my first solution. > A better solution may be to use Dir.chdir to change to the directory and > then use Dir.glob to extract the file names. This has the advantage of > not including the path in front of each file name. You can use Dir.entries for that: Dir.new("C:/Users/Public/Music/Sample Music").entries.grep /\.wma\z/i Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/