How to match filetype with regular expression?

Posted by Sanarothe on Stack Overflow See other posts from Stack Overflow or by Sanarothe
Published on 2010-04-10T08:09:45Z Indexed on 2010/04/10 8:13 UTC
Read the original article Hit count: 388

Filed under:
|

Hi. I'm stuck trying to get a regex to match a filetype in a sorting script.

Dir.foreach(savedirs[0]) do |x|
  puts "Matching " + x + " against filetypes."
  case x
  when x.match(/^.*\.exe$/i) then puts x
  when x.match(/\.jpe?g$/) then FileUtils.move(x, sortpath[".exe"], :verbose => true)
  when x =~ /\.jpg$/ then FileUtils.move(x, sortpath[".jpg"])
  end
end

I can't get any of these to match on in windows. All I need is to confirm that a given filename matches against compatible filetypes.

© Stack Overflow or respective owner

Related posts about regex

Related posts about ruby