Les Snippets

Connexion

Savoir si un chemin donnée est un fichier ou un répertoire

Niveau requis pour utiliser/comprendre cette source : 1 ( Débutant )
Créé le 14/10/2008 13:08:57 et initié par Willi [Liste]
Date de mise à jour : 21/10/2008 18:30:48
Vue : 1138
Catégorie(s) : Fichier / Disque
Langages dispo pour ce code :
- C# 1.x, C# 2.x, C# 3.x
- VB 2005, VB 2008, VB.NET 1.x
- VB6, VBA
- Delphi 5



Langage : C# 1.x , C# 2.x , C# 3.x
Date ajout : 14/10/2008
Posté par Willi [Liste]
Private static bool PathIsDirectory(string path)
{
     try
     {
          if(!System.IO.File.Exists(path))
          {
               return ((new System.IO.FileInfo(path).Attributes & System.IO.FileAttributes.Directory) == System.IO.FileAttributes.Directory) ? true: false;
          }
     }
     catch (Exception)
     {
          return false;
     }
}
Remarque :
exemple:
bool pathIsDir= PathIsDirectory(@"c:\toto\test.txt");
renvois false est indique qu'il s'agit d'un fichier.
Langage : VB.NET 1.x , VB 2005 , VB 2008
Date ajout : 14/10/2008
Posté par Willi [Liste]
Private Shared Function PathIsDirectory(ByVal path As String) As Boolean
  Try
    If Not System.IO.File.Exists(path) Then
      Return IIf(((New System.IO.FileInfo(path).Attributes And System.IO.FileAttributes.Directory) = System.IO.FileAttributes.Directory),True,False)
    End If
  Catch generatedExceptionName As Exception
    Return False
  End Try
End Function

Remarque :
Exemple:
Dim bIsDir = PathIsDirectory("C:\toto\MonDossier")
Renvoie true il s'agit bien d'un répertoire
Langage : VB6 , VBA
Date ajout : 21/10/2008
Posté par jrivet [Liste]
DateMAJ : 21/10/2008
Option Explicit
'utilisation renvoie False si le chemin passé
'n'est pas un répertoire
'MsgBox PathIsDirectory("C:\Toto")
Public Function PathIsDirectory(StrPath As String) As Boolean
On Error GoTo HandleError
    PathIsDirectory = ((GetAttr(StrPath) And vbDirectory) <> 0)
HandleError:
End Function
Langage : Delphi 5
Date ajout : 11/11/2008
Posté par f0xi [Liste]
FileExists(FileName); // true si FileName est un fichier 
DirectoryExists(PathName); // true si PathName est un repertoire


Snippets en rapport avec : Fichier, Répertoire, Chemin, Source



Codes sources en rapport avec : Fichier, Répertoire, Chemin, Source

{Visual Basic, VB6, VB.NET, VB 2005} COMPARATEUR EXCEL EN MASSE, AMÉLIORATIONS
mabrouklepoux avait proposé un comparateur de fichiers Excel. http://www.vbfrance.com/code.aspx?ID=3...

{Delphi} SYNCHRONISATION-FICHIERS (MODIFICATION DE TIGRIS1)
TIGRIS a écrit: "Il y a encore beaucoup de fonctions qui peuvent être ajoutées et il n'est pas im...

{Delphi} SYNCHRONISATION DE FICHIERS
Bonjour, Le programme de synchronisation de répertoires posté par akilavaca m'a donné des idées e...

{Visual Basic, VB6, VB.NET, VB 2005} REPLACE IN FILE - REMPLACEMENTS MULTIPLES DES FICHIERS D'UN RÉPERTOIRE
[VB6] Petit utilitaire pour remplacer du texte par un autre, plusieurs remplacements en cascades pos...

{C# / C#.NET} EFEXP - CONTRÔLE EXPLORATEUR DE FICHIER
Ce composant est un explorateur de fichier qui reprend les fonctionnalités de base de l'explorateur ...

{Visual Basic, VB6, VB.NET, VB 2005} CLASSE LISTE DE FICHIER RÉCURSIVE
Je poste ma version de la construction d'une liste de fichier à partir d'un répertoire, les fichiers...

{Python} RECHERCHE DE CHAINES DANS UN REPERTOIRE AVEC IGU
Ce script est destiné à la recherche de fichiers qui contiennent une chaîne de caractère dans un ens...

{C# / C#.NET} EXPLORATEUR DE FICHIER (CONTROLE)
Ma source est basé sur le code de la source http://www.csharpfr.com/codes/EXPLORATEUR-FICHIERS_42458...

{Visual Basic, VB6, VB.NET, VB 2005} MODIFICATIONS NOM DE FICHIERS DANS UN MÊME RÉPERTOIRE
C'est un tout petit code tout simple mais qui est pratique si on veut modifier rapidement les noms d...

{C / C++ / C++.NET} [C/WIN32] EFFACER FICHIERS/RÉPERTOIRES VIDES
Le code n'apporte rien de vraiment nouveau: Utilisation de FindFirstFile et FindNextFile, recherche...