Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

file.shortpath for vb.net

ho i'm converting a my project from vb6 to vb.net Is there an analog method in vb.net of shortpath?

Dim DestinationFile As Scripting.File
...
DestinationFile.ShortPath

Thanks

like image 718
Luca Romagnoli Avatar asked Mar 15 '26 00:03

Luca Romagnoli


1 Answers

No, modern languages are not built to use short paths, but you can use the GetShortPathName method from the kernel:

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

Call using:

Dim name As String = "C:\Long Directory Name\Really really long filename.txt"

Dim sb As New StringBuilder(256)
GetShortPathName(name, sb, sb.capacity)

Dim shortName As String = sb.ToString()
like image 112
Guffa Avatar answered Mar 17 '26 17:03

Guffa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!