Les Snippets

Connexion

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

Niveau requis pour utiliser/comprendre cette source : 1 ( Débutant )
Créé le 28/08/2007 21:18:10 et initié par PCPT [Liste]
Date de mise à jour : 24/10/2007 23:24:55
Vue : 4829
Catégorie(s) : API, Chaîne de caractères
Langages dispo pour ce code :
- VB6, VBA
- VB 2005, VB.NET 1.x
- C# 1.x, C# 2.x
- Voir tous les langages pour ce code snippet



Langage : C# 1.x , C# 2.x
Date ajout : 24/10/2007
Posté par Charles Racaud [Liste]
DateMAJ : 24/10/2007

[System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet=System.Runtime.InteropServices.CharSet.Auto)]

private static extern int GetShortPathName(
  string Path,
  System.Text.StringBuilder ShortPath,
  int ShortPathLength
);

public static string GetShortPathName_CreateDestroy(string Path) {
  bool fCreate = !System.IO.File.Exists(Path);
  if (fCreate)
    System.IO.File.Create(Path).Dispose();
  string shortPath = GetShortPathName(Path);
  if (fCreate)
    System.IO.File.Delete(Path);
  return shortPath;
}

public static string GetShortPathName(string Path) {
  System.Text.StringBuilder shortPath = new System.Text.StringBuilder(255);
  GetShortPathName(Path, shortPath, shortPath.Capacity);
  return shortPath.ToString();
}

Remarque :
La fonction GetShortPathName_CreateDestroy fait une vérification si le fichier existe, si non, le fichier est crée pour récupéré son chemin court puis est supprimé.
Tandis que la fonction GetShortPathName ne teste pas son existence. (Renvois "" si il n'existe pas)

Snippets en rapport avec : Fichier, Chemin, Récupérer, Short, Court



Codes sources en rapport avec : Fichier, Chemin, Récupérer, Short, Court

{Visual Basic, VB6, VB.NET, VB 2005} GETNAMES : RÉCUPÈRE ET ÉCRIT TOUS LES NOMS DE FICHIERS D'UN DOSSIER
J'ai fait ce petit programme tout simple, qui aurait pu être créé par n'importe quel débutant, car j...

{Visual Basic, VB6, VB.NET, VB 2005} NTFS RECOVER : RÉCUPÉRER LES FICHIERS EFFACÉS D'UNE PARTITION NTFS
Ce code permet de récupérer les fichiers effacés de vos partitions NTFS. Pour cela, vous devez avoir...

{Visual Basic, VB6, VB.NET, VB 2005} ALGORITHME DE PATHFINDING ASTAR
Cet algorithme célèbre est un algorithme de type PathFinding. Il recherche le chemin le plus rap...

{Delphi} ASTAR - A* RECHERCHE DU PLUS COURT CHEMIN
bonjour, je poste la source d'un A* codé l'an passé. C'était mon premier programme donc je me suis...

{Javascript / DHTML} RECHERCHE DU PLUS COURT CHEMIN - ALGO DE DIJKSTRA - EN JAVASCRIPT
L'algorithme de Dijkstra est aussi appelé algorithme de recherche du plus court chemin, il permet do...

{Visual Basic, VB6, VB.NET, VB 2005} CHERCHE LE CHEMIN LE PLUS COURT !
application de l'algorithme GREEDY (cherche un chemin pour arriver au sommet désiré)...

{C / C++ / C++.NET} DECOUPAGE CHEMIN FICHIER (FORUM)
Suite a une demande sur le forum, voila un code qui permet de découper le chemin d'un fichier en so...

{Foxpro} COMMENT ANALYSER LE CHEMIN D'UN FICHIER AVEC WINDOWS SCRIPTING HOST
Le code requiert l'installation de Windows Scripting Host Plateformes supportées: Windows Server...

{ColdFusion} RÉCUPÈRER LE CHEMIN D'UN FICHIER SUR LE SERVEUR DISTANT
L'utilisation de la balise CFFILE nécessite de connaître le chemin absolu pour uploader les fichi...

{Visual Basic, VB6, VB.NET, VB 2005} DRAG & DROP D'UN FICHIER ET EXTRACTION DU NOM ET DU CHEMIN
Ce code reprend une partie de l'exemple de Drag & Drop de la source de goth (voir le lien http://www...