Translate Between Short and Long Paths

It is sometimes necessary to convert between short and long paths. For example, in Win95/98, if the Path environment variable string exceeds 1024 bytes, the string gets truncated. Or, some apps do not accept long path names with spaces and short path names are required.

I wrote a simple dialog-based app that takes a path string as an input and produces the short and the long path names as an output. Nothing fancy here. Just plain vanilla code that might prove useful to someone.

For example entering: C:\Program Files\util\vslick\win;C:\Program Files\Microsoft Visual Studio\Common\Tools\WinNT;C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin;C:\Program Files\Microsoft Visual Studio\Common\Tools;C:\Program Files\Microsoft Visual Studio\VC98\bin;C:\PROGRA~1\STINGR~1\OE104\lib;C:\PROGRA~1\STINGR~1\Common\ COMMON~1.01\lib;C:\PROGRA~1\STINGR~1\Common\MVC6~1.01\lib;C:\PROGRA~1\STING R~1\OT601\lib

produces the long path as follows: C:\Program Files\util\vslick\win;C:\Program Files\Microsoft Visual Studio\Common\Tools\WinNT;C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin;C:\Program Files\Microsoft Visual Studio\Common\Tools;C:\Program Files\Microsoft Visual Studio\VC98\Bin;C:\Program Files\Stingray Objective Studio\OE104\Lib;C:\Program Files\Stingray Objective Studio\Common\Common 6.01\lib;C:\Program Files\Stingray Objective Studio\Common\MVC 6.01\lib;C:\Program Files\Stingray Objective Studio\OT601\lib

and the short path as follows: C:\PROGRA~1\util\vslick\win;C:\PROGRA~1\MICROS~2\Common\Tools\WinNT;C:\PROG RA~1\MICROS~2\Common\MSDev98\Bin;C:\PROGRA~1\MICROS~2\Common\Tools;C:\PROGR A~1\MICROS~2\VC98\bin;C:\PROGRA~1\STINGR~1\OE104\lib;C:\PROGRA~1\STINGR~1\C ommon\COMMON~1.01\lib;C:\PROGRA~1\STINGR~1\OT601\lib;q:\ntutil;q:\util;c:\t ools;q:\es\3rdparty\windows;q:\es\dev

Download demo project - 14 KB

Download demo application (sans source) - 8 KB

Date Last Updated: May 17, 1999



Comments

  • Damn Angry!

    Posted by Legacy on 01/27/2003 12:00am

    Originally posted by: Barbara Reynolds

    You have caused a virus on my computer.  I am not smart enough to fix it.  A virus notification shnows up and covers my desktop and any programs that I open.  I am more than angry.  At least tell me how to correct the problem.  The virus is C:\PROGRA 1\COMMON 1\media\otDock.dll
    
    

    Reply
  • Excellent work !

    Posted by Legacy on 07/04/2002 12:00am

    Originally posted by: Steven

    Just what I need ! (Because my OS is NT4)

    Reply
  • GetShortPathName does this for you!

    Posted by Legacy on 09/13/2000 12:00am

    Originally posted by: Bob Blais

    If I understand what you are trying to do, I would like to submit a function that does this automatically.
    
    

    ::GetShortPathName(oldname, newname, length of new name);

    This call automatically formats a long path, to the DOS short path representation.

    Reply
  • Windows 95 problem

    Posted by Legacy on 08/01/2000 12:00am

    Originally posted by: Mikkel Bie

    Tried to use your code, but on our Windows 95 testbox the call to SHGetPathFromIDListW was not supported. I used SHGetPathFromIDList instead, and it seems to solve the problem.
    -Mikkel

    Reply
  • Other Methods

    Posted by Legacy on 07/04/1999 12:00am

    Originally posted by: Trevor Ash

    you can use:
    
    

    GetShortPathName(longpath, shortpath, shortsize);
    GetLongPathName(longpath, shortpath, longsize);

    I've never used GetLongPathName, in fact it seems to be a
    new function in VC6. I have used GetShortPathName since
    VC4.2 and it works excellent.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • VMware vCloud® Government Service provided by Carpathia® is an enterprise-class hybrid cloud service that delivers the tried and tested VMware capabilities widely used by government organizations today, with the added security and compliance assurance of FedRAMP authorization. The hybrid cloud is becoming more and more prevalent – in fact, nearly three-fourths of large enterprises expect to have hybrid deployments by 2015, according to a recent Gartner analyst report. Learn about the benefits of …

Most Popular Programming Stories

More for Developers

RSS Feeds