11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/freespace.rb', line 11
def self.get_free_space(location,unit=nil)
stats = Filesystem.stat(location)
if unit == 'KB'
free_space = stats.blocks_available * stats.block_size / Freespace::KB
end
if unit == 'MB'
free_space = stats.blocks_available * stats.block_size / Freespace::MB
end
if unit == 'GB'
free_space = stats.blocks_available * stats.block_size / Freespace::GB
end
if unit == 'TB'
free_space = stats.blocks_available * stats.block_size / Freespace::TB
end
if unit == nil
unit = 'MB'
free_space = stats.blocks_available * stats.block_size / Freespace::MB
end
free_space_hash = { :free_space => free_space , :unit => unit }
return free_space_hash
end
|