Project

General

Profile

Feature #3356 » pathname-shortpath.rb

Monkey patch to pathname - docwhat (Christian Höltje), 05/28/2010 01:42 AM

 
##
# Pathname monkey-patch -- adds shortpath to Pathname
begin
require "Win32API"
rescue LoadError
Win32API = nil
end
require 'pathname'

class Pathname
# Returns a pathname object containing the windows short path.
# In unix, it returns a new pathname object.
def shortpath
if Win32API.nil?
return self.class.new(@path)
else
path = @path
win_func = Win32API.new("kernel32","GetShortPathName","PPL"," L")
max_path = 260

buf = 0.chr * max_path
buf[0..path.length-1] = path
win_func.call(path, buf, buf.length)
return self.class.new(buf.split(0.chr).first)
end
end
end
    (1-1/1)