sroller icon

Ruby: get drives on Windows

sroller | PRO | 04/04/17 09:48:49 PM UTC | 0 ⭐ | 541 👁️ | Never ⏰ | []
Ruby |

310 B

|

None

|

0 👍

/

0 👎

#!/usr/bin/env ruby
 
require 'win32/api'
include Win32
 
get_logical_drive_strings = API.new('GetLogicalDriveStrings', 'IP', 'I')
 
BUFLEN = 260
buf = 0.chr * BUFLEN
 
rc = get_logical_drive_strings.call(BUFLEN, buf)
if (0..BUFLEN) === rc
    puts buf[0..rc-1].split("\x00")
else
    puts "buffer too small"
end

Comments