note 11669 added to getcwd

From: Date: Thu, 01 Mar 2001 19:49:39 +0000
Subject: note 11669 added to getcwd
Groups: php.notes 
Request: Send a blank email to php-notes+get-11724@lists.php.net to get a copy of this message
A common task I have to script for is to do something to every directory or every file in a directory. Here is a bit of code I find useful. #!/usr/bin/php -q <? //right now $curdir is the current directory $curdir = getcwd(); $inputarray = opendir($curdir); $resultarray = array(); while($var = readdir($inputarray)) { //this checks that the var listed is a directory //but skips . and .. if(is_dir($curdir . "/" . $var)) { if($var != '.' && $var != '..') $resultarray[]=$curdir . "/" . $var; } } for($x = 0; $x < sizeof($resultarray); $x++) { //instead of just echoing to the screen //you could put code here to do something //to each directory like chown or mv echo $resultarray[$x] . "\n";; } ?> http://www.php.net/manual/en/function.getcwd.php

« previous php.notes (#11724) next »