sschuberth
sschuberth

Reputation: 29811

Ruby method for convering Windows short path into long path?

Is there a built-in method in Ruby to convert a Windows short path like

C:\PROGRA~2\MICROS~1.0\VC\bin\amd64

into its corresponding long path

C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64

I've tried

but none of these worked.

If possible, I'd like to avoid calling the Win32 API directly like in this answer, or ugly work-arounds like spawning PowerShell:

%x{powershell (Get-Item -LiteralPath #{short_path}).FullName}

Upvotes: 2

Views: 338

Answers (1)

kit.yang
kit.yang

Reputation: 2798

Here is one possible workaround:

path=Dir.mktmpdir('vendor')
=> "C:/Users/ADMINI~1/AppData/Local/Temp/1/vendor20160727-12668-ywfjol"

Dir.glob(path)[0]
=> "C:/Users/Administrator/AppData/Local/Temp/1/vendor20160727-12668-ywfjol"

Upvotes: 3

Related Questions