vb.net 的 file.shortpath

Luc*_*oli 3 vb.net vb6 file converters

我正在将我的项目从 vb6 转换为 vb.net vb.net 中的短路径有模拟方法吗?

Dim DestinationFile As Scripting.File
...
DestinationFile.ShortPath
Run Code Online (Sandbox Code Playgroud)

谢谢

Guf*_*ffa 5

不,现代语言不是为了使用短路径而构建的,但是您可以使用内核中的 GetShortPathName 方法:

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

呼叫使用:

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()
Run Code Online (Sandbox Code Playgroud)