Astuces de recherche...
Home
- Accueil & nouveautés
- Les newsgroups VB
- Téléchargements
- L'équipe
- Nous contacter
- Liens
Rubriques
- Toutes les questions
- Affichage & graphismes
- Algorithmique
- API
- Base de registre
- Bases de données
- Contrôles
- Date & heure
- Déploiement
- Divers
- Erreurs & problèmes
- Fichiers & dossiers
- Généralités
- Impression
- Internet & mails
- Math
- Multimédia
- Réseaux
- Structures de données
- Texte & strings
- VB .Net
- VB Script
- VBA
- Windows

Question 30

Comment trouver le nom court d'un fichier en fonction de son nom long ?

Il faut employer l'API GetShortPathName :

Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long

Const MAX_PATH_LENGHT = 255

Private Function ShortPath(LongPath As String) as String

    Dim tmpShortPath As String
    Dim RC As Long

    tmpShortPath = Space(MAX_PATH_LENGHT + 1)

    RC = GetShortPathName(LongPath, tmpShortPath, MAX_PATH_LENGHT + 1)

    ShortPath = Left(tmpShortPath, InStr(tmpShortPath, Chr$(0)) - 1)

End Function

Private Sub Form_Load()

    MsgBox ShortPath("C:\Mes Documents\LongNameFile.txt")

End Sub

Date de publication : 07 juillet 2002
Dernière modification : 07 juillet 2002
Rubriques : Fichiers & dossiers
Mots-clés : fichiers, dossiers, nom, court, long, GetShortPathName, longpath, shortpath