Récupérer un chemin de fichier au format Short (même si ce fichier n'existe pas)


Contenu du snippet

Shared Function GetShortPathName_CreateDestroy(ByVal Path As String) As String
  Dim fCreate As Boolean = Not System.IO.File.Exists(Path)
  If fCreate Then System.IO.File.Create(Path).Dispose()
  Dim shortPath As String = GetShortPathName(Path)
  If fCreate Then System.IO.File.Delete(Path)
  Return shortPath
End Function
Shared Function GetShortPathName(ByVal Path As String) As String
  Dim shortPath As New System.Text.StringBuilder(255)
  GetShortPathName(Path, shortPath, shortPath.Capacity)
  Return shortPath.ToString()
End Function
<System.Runtime.InteropServices.DllImport("kernel32.dll", SetLastError:=True, _
  CharSet:=System.Runtime.InteropServices.CharSet.Auto)> _
Private Shared Function GetShortPathName(ByVal Path As String, _
  ByVal ShortPath As System.Text.StringBuilder, _
  ByVal ShortPathLength As Integer) As Integer
End Function


Compatibilité : VB 2005, VB.NET 1.x

Disponible dans d'autres langages :

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.