?
Solved

Converting 8.3 paths to long paths

Posted on 1997-04-24
2
Medium Priority
?
572 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 200 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

770 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