How to find the DOS name of a file?

Posted on 1998-09-20
Last Modified: 2010-04-30
How do I find the MS-DOS filename of a file?
Question by:Olli083097

Expert Comment

ID: 1435754
Could you please clarify your question?

Expert Comment

ID: 1435755
Give example please!

Accepted Solution

clifABB earned 50 total points
ID: 1435756
Add the following code to the declarations section:
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long

The Add the following subroutine:
Private Function GetShortName(ByVal sLongFileName As String) As String
  Dim lRetVal As Long
  Dim sShortPathName As String
  Dim nLen As Integer

  'Set up buffer area for API function call return
  sShortPathName = Space(255)
  nLen = Len(sShortPathName)
  'Call the function
  lRetVal = GetShortPathName(sLongFileName, sShortPathName, nLen)
  'Strip away unwanted characters.
  GetShortName = Left(sShortPathName, lRetVal)
End Function

You can then call this function passing the long filename and it will return the short filename.

Author Comment

ID: 1435757

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

910 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

20 Experts available now in Live!

Get 1:1 Help Now