C
CSharp
C++
Java
Visual Basic
HTML - CSS
Android
Asp
Asp.Net
Php
Python
JavaScript
SQL
XML
Assembly
ActiveX
API
Code Snippets
Database
Files Directories Drives
Forms
Graphics Games
Multimedia
Strings
Windows and Controls
More...
Visual Basic > Files Directories Drives sample source codes
Visual Basic Code > Get the Short Path Name
Get the Short Path Name There comes a time when you just don't want a long file name. I myself had experienced some problems with my midi code because it wasn't working with long filenames. All you need to do is pass the long file name to the GetShortPathName API and it will return the short name. Place this code in a .bas module Option Explicit Public Declare Function GetShortPathName Lib "kernel32" _ Alias "GetShortPathNameA" _ (ByVal lpszLongPath As String, _ ByVal lpszShortPath As String, _ ByVal cchBuffer As Long) As Long Public Function GetShortName(sFile As String) As String Dim sShortFile As String * 67 Dim lResult As Long 'Make a call to the GetShortPathName API lResult = GetShortPathName(sFile, sShortFile, _ Len(sShortFile)) 'Trim out unused characters from the string. GetShortName = Left$(sShortFile, lResult) End Function Now place this code in the Form_Load event Private Sub Form_Load() Debug.Print GetShortName(App.Path) End Sub
Privacy Policy
|
Contact
|
Advertising
|
Link to Us
|
Directory