Les Snippets

Connexion

Génération récursive d'une arborescence de répertoires

Niveau requis pour utiliser/comprendre cette source : 2 ( Initié )
Créé le 23/01/2007 14:46:31 et initié par webdeb [Liste]
Vue : 12121
Catégorie(s) : Fichier / Disque, Algorithme, Regex
Langages dispo pour ce code :
- PHP 3, PHP 4, PHP 5
- VB6, VBA



Langage : PHP 3 , PHP 4 , PHP 5
Date ajout : 23/01/2007
Posté par webdeb [Liste]
<?php
/**********************************************************
* Name      : setDirTree()
* Aim      : recursie function which generates a directories 
*           tree
*
* Params : string $_dirTree
* Return : void
* Author : Hugo 'Emacs' HAMON
* Web    : http://www.hugohamon.com
**********************************************************/
function setDirTree($_dirTree) {
    // Is parameter null or empty ?
    if(!empty($_dirTree) && is_string($_dirTree)) {
   
        // Check if the root directory exists in the string
        if(preg_match('`^\.\/[^\.\.\/]`si'$_dirTree)) {
            // Go to the root directory
            chdir('.');
            // Delete the root element
            $_dirTree str_replace('./','',$_dirTree);
        }
        
        // Check if symbolic links exist in the string
        if(preg_match('`^(\.\/)?[\.\.\/]{1,}`si'$_dirTree$matches)) {
        
            chdir($matches[0]);
            $_dirTree str_replace($matches[0],'',$_dirTree);
        }
        // Explode the string as an array
        $path explode('/'$_dirTree);
        // Check if the directory exists
        if(!is_dir($path[0])) {
            // Create directory
            mkdir($path[0]);
        }
        // Move inside it
        chdir($path[0]);
        // Delete the first array entry
        array_shift($path);
        // Implode the array as a string
        $path implode('/'$path);
        // Recursive call
        setDirTree($path);
    }
}
?>

Langage : VB6 , VBA
Date ajout : 17/01/2008
Posté par Renfield [Liste]
Private Declare Function MkDir Lib "imagehlp.dll" Alias "MakeSureDirectoryPathExists" (ByVal lpPath As String) As Long
Remarque :
remplace la fonction MkDir (non récursive) de base)

Snippets en rapport avec : Fichier, Répertoire, Arborescence, Génération, Root



Codes sources en rapport avec : Fichier, Répertoire, Arborescence, Génération, Root

{PHP} GÉNÉRATION RÉCURSIVE D'UNE ARBORESCENCE DE RÉPERTOIRES
Je vous présente une petite fonction récursive que j'ai développée pour permettre de générer l'arbor...

{Visual Basic, VB6, VB.NET, VB 2005} LISTE DES FICHIERS ET SOUS RÉPERTOIRES POUR VERSER DANS EXCEL
A partir d'un répertoire, descent toute l'arborescence et liste les fichiers et sous répertoires tro...

{C# / C#.NET} CHECK IDENTICAL FILES
Juste un petit code d'avant vacances qui permet de lister les fichiers identiques dans un répertoire...

{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...