From: Peter Bailey Date: 2013-01-10T01:00:54+09:00 Subject: Re: One liner for filenames "Jesús Gabriel y Galán" wrote in post #1091607: > On Wed, Jan 9, 2013 at 4:09 PM, Robert Klemme > wrote: >>> ... >>> >>> 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)' > > Careful, as this skips also filename_11.png, filename_21.png, etc. > Building on this: > > ruby -r pathname -e 'Pathname.glob("*_{[^1],??}.png").each(&:delete)' > > Jesus. Excellent. Thanks. Hans is right, though. Dir.glob is unsorted. Is that a problem here? -- Posted via http://www.ruby-forum.com/.