【问题标题】:Ruby Get Available Disk DrivesRuby 获取可用的磁盘驱动器
【发布时间】:2011-03-16 13:40:50
【问题描述】:

谁能告诉我如何获取 ruby​​ 中可用磁盘驱动器的列表?我正在创建一个打开的文件对话框,需要知道!在此先感谢,呃。

【问题讨论】:

  • 这是在 windows/linux/mac osx 上吗?如果是 Windows,请查看此帖子:ruby-forum.com/topic/88875#170688
  • 是的,是windows,非常感谢,你帮了大忙,我很感激!

标签: ruby list disk drives


【解决方案1】:

Brian 给出的文章正确地陈述了以下代码:

require 'win32ole'

file_system = WIN32OLE.new("Scripting.FileSystemObject")
drives = file_system.Drives
drives.each do |drive|
  puts "Available space: #{drive.AvailableSpace}"
  puts "Drive letter: #{drive.DriveLetter}"
  puts "Drive type: #{drive.DriveType}"
  puts "File system: #{drive.FileSystem}"
  puts "Is ready: #{drive.IsReady}"
  puts "Path: #{drive.Path}"
  puts "Root folder: #{drive.RootFolder}"
  puts "Serial number: #{drive.SerialNumber}"
  puts "Share name: #{drive.ShareName}"
  puts "Total size: #{drive.TotalSize}"
  puts "Volume name: #{drive.VolumeName}"
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-15
    • 2017-01-27
    • 1970-01-01
    • 2014-12-01
    • 2011-04-26
    • 1970-01-01
    • 2012-04-11
    相关资源
    最近更新 更多