Advertisement
Guest User

Rrush

a guest
Jul 5th, 2020
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.70 KB | None | 0 0
  1. file_name = ARGV[0]
  2.  
  3. if file_name == nil
  4.     abort "Введите имя файла, как параметр"
  5. end
  6.  
  7. current_path = File.dirname(__FILE__)
  8. file_path = current_path + "/test.txt"
  9.  
  10. if File.exist?(file_path)
  11.  
  12.     # file = File.new(file_path, "r:UTF-8")
  13.     puts "Вы открыли файл - #{file_path}"
  14.     lines = File.readlines(file_path)
  15.     puts "Всего строк в файле: #{lines.size}"
  16.  
  17.     empty_lines = []
  18.  
  19.     for line in lines do
  20.         if line == "\n"
  21.              empty_lines.push("")
  22.         end
  23.     end
  24.     puts "Количество пустых строк: #{empty_lines.size}"
  25.     puts "Последние пять строк:"
  26.     puts
  27.     puts lines.last(5)
  28. else
  29.     puts "Файла нет"
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement