Solved

Long name from DOS short name

Posted on 2002-05-16
6
205 Views
Last Modified: 2013-11-20
Hi - Say that I have a CString that contains a valid file name, but it uses the short name like "C:\progra~1\my~1.txt"

How can I get a CString that looks like:
1 - "C:\Program Files\My File.txt"

and (not required, but would be nice)

2 - "\\mymachine\c\Program Files\My File.txt"

My main target is NT4.0.

Any help would be great.
0
Comment
Question by:marcus78
  • 3
  • 2
6 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 75 total points
ID: 7014290
Use 'GetShortPathName()':

GetShortPathName
The GetShortPathName function obtains the short path form of a specified input path.

DWORD GetShortPathName(
  LPCTSTR lpszLongPath,  // pointer to a null-terminated path string
  LPTSTR lpszShortPath,  // pointer to a buffer to receive the
                         // null-terminated short form of the path
  DWORD cchBuffer        // specifies the size of the buffer pointed
                         // to by lpszShortPath
);
 
Parameters
lpszLongPath
Pointer to a null-terminated path string. The function obtains the short form of this path.
lpszShortPath
Pointer to a buffer to receive the null-terminated short form of the path specified by lpszLongPath.
cchBuffer
Specifies the size, in characters, of the buffer pointed to by lpszShortPath.
0
 
LVL 86

Expert Comment

by:jkr
ID: 7014297
0
 
LVL 3

Expert Comment

by:Crius
ID: 7014399
I think you have it backwards jkr. :) I believe marcus78 wants GetLongPathName() instead...
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 86

Expert Comment

by:jkr
ID: 7014419
You are right :o)
0
 

Author Comment

by:marcus78
ID: 7014421
Crius, you're right I do want the long path, just haven't been able to try it out yet.  I'll get back to you and jkr later.
0
 

Author Comment

by:marcus78
ID: 7015443
Crius, GetLongPathName() isn't supported in NT 4.0, so I couldn't use that.  Thanks for pointing it out though.

jkr, while GetShortPathName was the opposite of what I needed, it put me on the right track to end up using FindFirstFile.  I was able to use this to determine the long path in NT 4.0.  Thanks for your help!

Marcus
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 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

19 Experts available now in Live!

Get 1:1 Help Now