Solved

Converting 8.3 paths to long paths

Posted on 1997-04-24
2
565 Views
Last Modified: 2013-12-04
Hello:

     I need a way to convert 8.3 shorten paths (windows 95 paths containing ~1 at the end) to their long names.  There is a function in Win32 api, called GetShortPathName() which converts a long path to a short one.  There's also a function called GetFullPathName() but that seems to do absolutely nothing.  It has 4 parameters, filename, size of path buffer, path buffer, and buffer to recieve the 'full' filename.  I've tried everything, but can't seem to get it to work properly.  If someone could show me how to do this correctly (C win32 API) I would appreciate it.  Example:
       I need to convert the directory of "Exampl~1" (dos 8.3 name) to "Example of long directory name" (long file name).
            Thanks, phuene
0
Comment
Question by:phuene
2 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 100 total points
ID: 1396920
There is a program to do so written by Jeffrey Richter published on MSJ May 1997 Vol 12 No 5. I modified the program and wrote a function as the following.

DWORD WINAPI ShortPathToLongPath(LPCTSTR lpszShortPath,
                                 LPTSTR lpszLongPath, DWORD cchBuffer)
{
    // Ensure that the string is Unicode.
    WCHAR wszShortPath[MAX_PATH];
    ::MultiByteToWideChar(CP_ACP, 0, lpszShortPath, -1,
                              wszShortPath, MAX_PATH);

      // Get the Desktop's shell folder interface
      LPSHELLFOLDER psfDesktop = NULL;
      HRESULT hr = ::SHGetDesktopFolder(&psfDesktop);

      // Request an ID list (relative to the desktop) for the short pathname
      ULONG chEaten = 0;
      LPITEMIDLIST pidlShellItem = NULL;
      hr = psfDesktop->ParseDisplayName(NULL, NULL, wszShortPath, &chEaten,
                                          &pidlShellItem, NULL);

      // Release the desktop's IShellFolder
      psfDesktop->Release();

      if (SUCCEEDED(hr))
      {
            // We did get an ID list, convert it to a long pathname
            CHAR szLongPath[MAX_PATH];
            ::SHGetPathFromIDList(pidlShellItem, szLongPath);

            // Free the ID list allocated by ParseDisplayName
            LPMALLOC pMalloc = NULL;
            ::SHGetMalloc(&pMalloc);
            pMalloc->Free(pidlShellItem);
            pMalloc->Release();

            // copy the long pathname
            DWORD dwCopy = min(::lstrlen(szLongPath) + 1, cchBuffer);
            :: lstrcpyn(lpszLongPath, szLongPath, dwCopy);

            return dwCopy;
      }
      else
            return 0;
}

0
 

Author Comment

by:phuene
ID: 1396921
Thanks, exactly what I was looking for.
       Regards, phuene
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now