I want to convert long filenames/path to short filenames (8.3). I'm developing a script that calls a command line tool that only accepts short filenames.
So i need to convert
C:\Ruby193\bin\test\New Text Document.txt
to
C:\Ruby193\bin\test\NEWTEX~1.TXT
So far i found How to get long filename from ARGV which uses WIN32API to convert short to long filenames (the opposite of what I want to achieve).
Is there any way to get the short filename in Ruby?
This ruby code uses getShortPathName and don't need additional modules to be installed.
You can do this using FFI; there's actually an example that covers your exact scenario in their wiki under the heading "Convert a path to 8.3 style pathname":
The windows function you require is GetShortPathName. You could use that in the same manner as described in your linked post.
EDIT: sample usage of GetShortPathName (just as a quick example) - shortname will contain "C:\LONGFO~1\LONGFI~1.TXT" and returned value is 24.