note 11669 deleted from function.getcwd by sniper
| From: | sniper@php.net | Date: | Tue, 04 Nov 2003 00:19:12 +0000 |
| Subject: | note 11669 deleted from function.getcwd by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-59744@lists.php.net to get a copy of this message | ||
Note Submitter: kingmundi@hotmail.com
----
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";;
}
?>