IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Développement Windows Discussion :

Repertoire parent d'un fichier


Sujet :

Développement Windows

  1. #1
    Membre averti
    Homme Profil pro
    Ingénieur Développement Logiciel
    Inscrit en
    Septembre 2005
    Messages
    285
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : Côte d'Ivoire

    Informations professionnelles :
    Activité : Ingénieur Développement Logiciel
    Secteur : Service public

    Informations forums :
    Inscription : Septembre 2005
    Messages : 285
    Points : 421
    Points
    421
    Par défaut Repertoire parent d'un fichier
    bonjour à tous,
    je présente mon problème

    j'ai des fichiers stocker dans un répertoire avec des sous repertoires
    Directory
    -sDirectory
    --ssDirectory
    ---fichier1
    ---fichier2

    ce qui donne pour le full path du fichier1: "C:\Directory\sDirectory\ssDirectory\fichier1" de même que pour le fichier2

    je souhaite extraire les infos suivantes du fullpath:
    p1="Directeory"
    p2="sDirectory"
    p3="ssDirectory"
    p4="fichier1"

    etc.

    Mon problème c'est que mon code me ramène:

    p1="C:\Directeory"
    p2="C:\Directory\sDirectory"
    p3="C:\Directory\sDirectory\ssDirectory"
    p4="C:\Directory\sDirectory\ssDirectory\fichier1"

    voilà mon code:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
     
    private void rechercheDossier(string rep) {
                string[] fichiers,repertoires;
                string CodeImage = null, p1= null, p2= null, p3= null, p4= null;
                //int i, j;
                int col, lign;
                try
                {
                    fichiers = System.IO.Directory.GetFiles(rep);
                    repertoires = System.IO.Directory.GetDirectories(rep);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    return;
                }
                foreach (string fichier in fichiers) {
                    System.IO.FileInfo fInfo = new System.IO.FileInfo(fichier);
                }
                foreach (string repertoire in repertoires) {
                    rechercheDossier(repertoire);
                }
                // Ajout des fichiers dans une listebox
                foreach (string fichier in fichiers) {
     
                    p1= folderFromFileName(folderFromFileName(folderFromFileName(fichier)));
                    p2= folderFromFileName(folderFromFileName(fichier));
                    p3= folderFromFileName(fichier);               
                    p4= nameOnlyFromFullPath(fichier);
     
                    lbFichiers.Items.Add(p1+ " -" + p2+" -" + p3+" -" + p4 );
                }
            }
     
     private string nameOnlyFromFullPath(string FileFullPath)
            {
                int intPos=0;
                string strSep = "\\";
                char[] any_Of = strSep.ToCharArray();
                intPos=FileFullPath.LastIndexOfAny(any_Of);
                intPos += 1;
                return FileFullPath.Substring(intPos,(Strings.Len(FileFullPath) - intPos));
            }
     
            private string dirParentFromFullPath(string fileFullPath) {
                int intPos = 1;
                string strSep = "\\";
                char[] any_Of = strSep.ToCharArray();
                intPos += 1;
                intPos = fileFullPath.LastIndexOfAny(any_Of);
                return fileFullPath.Substring(intPos, (Strings.Len(fileFullPath) - intPos));
            }
    Merci d'avance!

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Juillet 2005
    Messages
    351
    Détails du profil
    Informations personnelles :
    Âge : 57
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations forums :
    Inscription : Juillet 2005
    Messages : 351
    Points : 333
    Points
    333
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    Dim Champ_str() As String
    Champ_str = Split(Ligne_str, "\")
    dans Champ_str(0) tu devrais avoir c:
    dans Champs_str(1) Directeory etc...

  3. #3
    Membre averti
    Homme Profil pro
    Ingénieur Développement Logiciel
    Inscrit en
    Septembre 2005
    Messages
    285
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : Côte d'Ivoire

    Informations professionnelles :
    Activité : Ingénieur Développement Logiciel
    Secteur : Service public

    Informations forums :
    Inscription : Septembre 2005
    Messages : 285
    Points : 421
    Points
    421
    Par défaut
    merci j'essaie et fait un retour!

  4. #4
    Membre averti
    Homme Profil pro
    Ingénieur Développement Logiciel
    Inscrit en
    Septembre 2005
    Messages
    285
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : Côte d'Ivoire

    Informations professionnelles :
    Activité : Ingénieur Développement Logiciel
    Secteur : Service public

    Informations forums :
    Inscription : Septembre 2005
    Messages : 285
    Points : 421
    Points
    421
    Par défaut
    Merci beaucoup voila ce que ça donne en c#

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    string _str = "\\";
    char[] any_of = _str.ToCharArray();
    string[] strChamp = fichier.Split(any_of);
    Et ça marche.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [VBA-E] Parcourir un repertoir et opérations sur fichiers xls
    Par anisr dans le forum Macros et VBA Excel
    Réponses: 17
    Dernier message: 08/03/2007, 17h48
  2. Réponses: 3
    Dernier message: 12/12/2006, 10h49
  3. Supprimer un répertoire à 200 000 fichiers
    Par Galeenet dans le forum Shell et commandes GNU
    Réponses: 3
    Dernier message: 10/11/2006, 18h26
  4. changer le repertoire courant d'un fichier
    Par Iria77 dans le forum Général Python
    Réponses: 3
    Dernier message: 27/09/2006, 12h17
  5. Recuperation de l'inoeud du repertoire parent
    Par nicolaskarp dans le forum Linux
    Réponses: 4
    Dernier message: 07/01/2006, 01h37

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo