Skip to content

Instantly share code, notes, and snippets.

Created April 18, 2014 01:01
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
#! /usr/bin/ruby
# lsnote.rb
# カレントディレクトリ中の
# book-001.txt, book-002.txt, book-004.txt, book-005.txt
# teaching-003.txt, teaching-004.txt, teaching-005.txt, teaching-006.txt, teaching-009.txt
# writing-001.txt, writing-002.txt, writing-003.txt, writing-008.txt, writing-009.txt
# のようなファイルから、コーナー(book,teaching,writing)ごとに番号の最も大きなものを見つけ、
# タイムスタンプ順に表示する。
require 'pathname'
latest =
Dir.glob('*.txt').each do |filename|
if filename.match(/^(\w+)-/)
corner = $1
if !latest[corner] or latest[corner] < filename
latest[corner] = filename
end { |f| }.sort { |a, b| a.ctime <=> b.ctime }.each do |pathname|
puts "#{pathname.ctime} #{pathname}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment