From: Robert Klemme Date: 2013-01-10T00:09:50+09:00 Subject: Re: One liner for filenames On Tue, Jan 8, 2013 at 9:48 PM, Peter Bailey wrote: > Hello, > Can someone help me to write a Ruby one-liner to remove all the files > except one in a list of files? I have a list of pages of an original > PDF. Each page has been converted to a PNG file. They're each numbered > with an underscore and a number at their end. > > filename_1.png > filename_2.png > filename_3.png > ... > > I need to basically delete all of the files except for the first one, > the one with the "_1" suffix at the end. Can I do that wiith a > one-liner? ruby -r pathname -e 'Pathname.glob("*[^1].png").each(&:delete)' Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/