Solved

Converting 8.3 paths to long paths

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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
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…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

832 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