在 ruby 中获取可用磁盘空间 [英] Get available diskspace in ruby
本文介绍了在 ruby 中获取可用磁盘空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 ruby 获取磁盘空间信息的最佳方法是什么.我更喜欢纯红宝石解决方案.如果不可能(即使使用额外的 gem),它也可以使用标准 ubuntu 桌面安装中可用的任何命令将信息解析为 ruby.
What is the best way to get diskspace information with ruby. I would prefer a pure ruby solution. If not possible (even with additional gems), it could also use any command available in a standard ubuntu desktop installation to parse the information into ruby.
推荐答案
您可以使用 sys-filesystem gem(跨平台友好)
You could use the sys-filesystem gem (cross platform friendly)
require 'sys/filesystem'
stat = Sys::Filesystem.stat("/")
mb_available = stat.block_size * stat.blocks_available / 1024 / 1024
这篇关于在 ruby 中获取可用磁盘空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文