Skip to content

Instantly share code, notes, and snippets.

@kcassam
Last active December 25, 2015 00:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kcassam/6885882 to your computer and use it in GitHub Desktop.
Save kcassam/6885882 to your computer and use it in GitHub Desktop.
itérer récursivement sur un dossier en php

Pour itérer récursivement sur un dossier en php, vous pouvez utiliser le code suivant :

$iterator = new RecursiveIteratorIterator(
    new RecursiveDirectoryIterator($pathname), 
    RecursiveIteratorIterator::SELF_FIRST
); 

Exemple : Changer les droits des éléments inclus dans un dossier :

$pathname = "/chemin/du/dossier/";
$iterator = new RecursiveIteratorIterator(
    new RecursiveDirectoryIterator($pathname), 
    RecursiveIteratorIterator::SELF_FIRST
); 
foreach($iterator as $item) { 
  chmod($item, 0777);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment