Solved

Converting 8.3 paths to long paths

Posted on 1997-04-24
2
564 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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 tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

10 Experts available now in Live!

Get 1:1 Help Now