From: tamouse mailing lists Date: 2012-12-29T13:46:08+09:00 Subject: Re: "unless" with Regex On Fri, Dec 28, 2012 at 7:04 PM, Pierre-Andre M. wrote: > That worked perfectly thank you....as a follow up, for some reason the > filename "." and ".." are still showing their pesky heads through: > > I tried elimating them using the same syntax but didnt work: > > if name != /^\.{1,}$/ > > > here is the whole code-snippet: > > Dir.foreach("/Volumes/gac_repo/video") do |folder_names| > if folder_names =~ /^\d{4}$/ > year = folder_names > puts "The folder name is: #{year}" > Dir.foreach("/Volumes/gac_repo/video/#{year}") do |name| > if name != /^\.{1,}$/ > puts "The file name is #{name}" > end > end > end > end Wondering if I understand this, wouldn't this give you what you want? path = "/Volumes/gac_repo/video" years_pattern = "[12][0-9][0-9][0-9]" Dir.glob("#{path}/#{years_pattern}/") do |folder| puts "The folder name is #{folder}" Dir.glob("#{folder}*") do |file| puts "The file name is #{file}" if File.file?(file) end end The first Dir.glob will provide the directories that make years assuming they are all 4 digit years > year 1000 (safe bet if they're videos). The second Dir.glob will give all non-hidden (non-dot) files, directoires, named pipes, etc, which is why you may want the if modifier File.file?, which returns true only for actual files, not directories or named pipes, etc. (If that is not true, adjust accordingly.)