Skip to content

Instantly share code, notes, and snippets.

@hyuki0000
Created April 18, 2014 01:01
Embed
What would you like to do?
lsnote.rb
#! /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 = Hash.new(nil)
Dir.glob('*.txt').each do |filename|
if filename.match(/^(\w+)-/)
corner = $1
if !latest[corner] or latest[corner] < filename
latest[corner] = filename
end
end
end
latest.values.map { |f| Pathname.new(f) }.sort { |a, b| a.ctime <=> b.ctime }.each do |pathname|
puts "#{pathname.ctime} #{pathname}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment