Title photo
frugal technology, simple living and guerrilla large-appliance repair
Mon, 12 Sep 2016

Using Dir.glob to delete files with a pattern in Ruby

I have a bunch of files in a directory, and I want to delete all that begin their filename with the letters X16 (e.g. X16data.xml)

I used Dir.glob to select the files and iterated over what comes up in the pattern, using File.delete to get rid of what I don't want (Thanks, Stack Overflow):

Dir.glob("X16*") do |file|

You can put any kind of regex in here, and it'll probably work. That's the theory anyway.