Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [RUBY CODE]
- #!/usr/local/bin/ruby
- def file_contents(file)
- File.open(file, 'r') do |f|
- f.each_line do |line|
- return line
- end
- end
- end
- @hash = {}
- def populate_and_sort_hash
- Dir.entries('.').each do |f|
- next if !f.match(/(a|b|c|d|e).txt/)
- @hash[f] = file_contents(f) if !File.directory? f
- end
- puts @hash.sort_by{|k,v| v}
- end
- populate_and_sort_hash
- [OUTPUT]
- aguevara@anthony ~/Documents/Bash/Temp $ ruby Test.rb
- d.txt
- Mar 05 13:00
- b.txt
- Mar 08 18:00
- c.txt
- Mar 10 20:00
- e.txt
- Mar 12 14:00
- a.txt
- Mar 15 19:15
Add Comment
Please, Sign In to add comment