Solved

Converting 8.3 paths to long paths

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get a List of Executing Stored Procedures on Sql Server 2008 R2 5 65
Duplicates in Aggregate Query 3 50
Windows 10 Scheduled Tasks 11 105
SSRS Deployment problem 5 96
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

733 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