Solved

Long name from DOS short name

Posted on 2002-05-16
6
210 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Pressing cancel button with C# UI Automation 3 70
method notes when mouse over in eclipse 5 87
modThree challenge 4 91
"Black Box" Testing of Control System Software 2 51
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 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