Skip to content

Instantly share code, notes, and snippets.

@huseyin
Last active August 29, 2015 14:15
Show Gist options
  • Save huseyin/86051b01b957117c2a0f to your computer and use it in GitHub Desktop.
Save huseyin/86051b01b957117c2a0f to your computer and use it in GitHub Desktop.
Dosya ile ilgili bilgi döndüren betik
# encoding: UTF-8
#
require_relative 'file-about'
print "Path: "
input = gets.chomp
instance = Cisymic.new(input, "kilobyte")::chester
print """
**************************
File name : %s
Size : %3.2f
Lines : %d
Words : %d
Bytes : %d
**************************
""" %[instance[0], instance[1], instance[2], instance[3], instance[4]]
# encoding: UTF-8
class Cisymic
def initialize(path=nil, pita=nil)
@path = path
@pita = pita
end
def chester
results = Array.new
type = Hash.new
if @path.include?("/")
begin
file = File.open(@path, "r").readlines
name = @path.split("/")[-1]
summary = name
rescue
return NameError
end
else
begin
pathica = (`pwd`).chomp
file = File.open("#{pathica}/#{@path}", "r").readlines
summary = @path
rescue
return NameError
end
end
c0, c1, c2 = 0, 0, 0
length = file.size
while c0 < length
c1 = c1 + file[c0].size
c2 = c2 + file[c0].split.size
c0 += 1
end
lenB = Float(c1) # Bayt
lenK = c1 / Float(1024) # Kilobayt
lenM = c1 / Float(1024 * 1024) # Megabayt
type['byte'] = lenB
type['kilobyte'] = lenK
type['megabyte'] = lenM
if @pita != nil
results << summary << type[@pita] << length << c2 << c1
else
results << summary << lenB << length << c2 << c1
end
return results
# 'results' dizi olarak döndürülür.
# Döndürülen dizi, [file_name, file_size, line_size, word_size, bytes] şeklindedir.
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment