GetShortPathName API function

  • Thread starter Sakharam Phapale
  • Start date
S

Sakharam Phapale

Hi All,

I have following code which is not working

Declare Function GetShortPathName Lib "kernel32" _

Alias "GetShortPathNameA" (ByVal lpszLongPath As String, _

ByRef lpszShortPath As String, ByVal cchBuffer As Integer) As Integer



Dim lRetVal As Long, sShortPathName As String, iLen As Integer

Try

sShortPathName = Space(255)

iLen = Len(sShortPathName)

If Has_Space(sLongFileName) Then

lRetVal = GetShortPathName(sLongFileName, sShortPathName, iLen)

End If



GetShortName = Left(sShortPathName, lRetVal)



sShortPathName contains blank.
 
T

Tom Shelton

Declare Function GetShortPathName Lib "kernel32" _

Alias "GetShortPathNameA" (ByVal lpszLongPath As String, _

ByRef lpszShortPath As String, ByVal cchBuffer As Integer) As Integer

Option Strict On
Option Explicit On

Imports System.IO
Imports System.Text

Module Module1

Declare Auto Function GetShortPathName Lib "kernel32" _
(ByVal lpszLongPath As String, _
ByVal lpszShortPath As System.Text.StringBuilder, _
ByVal cchBuffer As Integer) As Integer

Const MAX_PATH As Integer = 260
Sub Main()
Dim path As String = "c:\documents and settings\tom\application
data"
Dim shortPath As New System.Text.StringBuilder(MAX_PATH)
GetShortPathName(path, shortPath, shortPath.Capacity)
Console.WriteLine(shortPath.ToString())
Console.ReadLine()
End Sub

End Module

HTH
 
S

Sakharam Phapale

Thanks Tom,

Actually previously I wanted to save a file and I gave it whole to the API
function.
since file was not exist function returns nothing.
So now I am passig only folder name to function and it returns correct one.

But my problem is if I want to save file as "c:\my folder\test file.wav"
Still file does not exist and I want short path name.
How to get that?

Thanks and Regards
Sakharam Phapale
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top