note 36643 added to class.dir

From: Date: Fri, 17 Oct 2003 04:01:15 +0000
Subject: note 36643 added to class.dir
Groups: php.notes 
Request: Send a blank email to php-notes+get-58740@lists.php.net to get a copy of this message
that recursive_ls works great on a UNIX system, but not on a Windows one. You'll find that you have to change the "/" in the two lines of the function to "\\" (at least on my version of PHP). And since Windows reports directory names as "DirName" instead of "DirName\" (at least on my version) you'll have to move around the "\\" a little bit as well. Here is the version that I got to work on my system: <? function recursive_ls($listing, $directory, $count) { $dummy = $count; if ($handle = opendir($directory)) { while ($file = readdir($handle)) { if ($file=='.' || $file=='..') continue; elseif ($h = @opendir($directory."\\".$file)) { closedir($h); $count = -1; $listing["$file"] = array(); recursive_ls(&$listing["$file"], $directory."\\".$file, $count + 1); } else { $listing[$dummy] = $file; $dummy = $dummy + 1; } } } closedir($handle); return ($listing); } //Example call $testlist = recursive_ls($direcs, "E:\\unsorted\\messedup", 0); ?> ---- Manual Page -- http://www.php.net/manual/en/class.dir.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+36643 Delete -- http://master.php.net/manage/user-notes.php?action=delete+36643&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+36643&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#58740) next »