Created
April 18, 2014 01:01
-
-
Save hyuki0000/11019650 to your computer and use it in GitHub Desktop.
lsnote.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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