electronish Posted December 5, 2006 Share Posted December 5, 2006 Hi .. I am trying to list all the files and folders in a specified root folder .. can u please help ? I am trying to do it since some days now and getting errors .. Previous programs could get the files in a folder but couldnt open a subfolder. Nw this one opens a subfolder But only two step down Can someone help with a better alternative ?[code]<?php chdir('D:\Myvideo');$scanthis = getcwd();scan_dir($scanthis);function scan_dir($scanthis){ $dir = @opendir($scanthis); while (false!=($file = @readdir($dir))) { if ($file != "." && $file != "..") { $type = filetype($file); echo "<br>file is $file and it is a $type <br>"; if($type == "dir" ) { $scanthisdir = $scanthis . "/" . $file; print "<br><b>this is $scanthisdir for the subfolder</b><br>"; scan_subdir($scanthisdir); } }}}function scan_subdir($scanthisdir){$dir = @opendir($scanthisdir); while (false!=($file = @readdir($dir))) { if ($file != "." && $file != "..") { $type = filetype($file); echo "<br>file is $file and it is a $type <br>"; if($type == "dir" ) { $scanthisdir = $scanthisdir . "/". $file; print "<br><b>this is $scanthisdir new for the subfolder</b><br>"; scan_subdir($scanthisdir); } counter(); } }}?>[/code]PS : i am only 10 days old with PhP .. so its not at all professional !!! Help Quote Link to comment https://forums.phpfreaks.com/topic/29591-cannot-go-into-a-subdirectory/ Share on other sites More sharing options...
electronish Posted December 6, 2006 Author Share Posted December 6, 2006 Should i use an array ? Quote Link to comment https://forums.phpfreaks.com/topic/29591-cannot-go-into-a-subdirectory/#findComment-135789 Share on other sites More sharing options...
genericnumber1 Posted December 6, 2006 Share Posted December 6, 2006 http://de.php.net/manual/en/function.scandir.phpIf you look at the comments there they have some ways of doing what I think you want to do. Quote Link to comment https://forums.phpfreaks.com/topic/29591-cannot-go-into-a-subdirectory/#findComment-135792 Share on other sites More sharing options...
Daniel0 Posted December 6, 2006 Share Posted December 6, 2006 scandir is PHP5 and higher, but you can use this snippet to ensure that it exists (from PHP manual comments): [code]<?phpif(!function_exists('scandir')) { function scandir($dir, $sortorder = 0) { if(is_dir($dir)) { $dirlist = opendir($dir); while( ($file = readdir($dirlist)) !== false) { if(!is_dir($file)) { $files[] = $file; } } ($sortorder == 0) ? asort($files) : rsort($files); // arsort was replaced with rsort return $files; } else { return FALSE; break; } }}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/29591-cannot-go-into-a-subdirectory/#findComment-135794 Share on other sites More sharing options...
electronish Posted December 6, 2006 Author Share Posted December 6, 2006 [quote author=Daniel0 link=topic=117494.msg479399#msg479399 date=1165364208]scandir is PHP5 and higher, but you can use this snippet to ensure that it exists (from PHP manual comments): [code]<?phpif(!function_exists('scandir')) { function scandir($dir, $sortorder = 0) { if(is_dir($dir)) { $dirlist = opendir($dir); while( ($file = readdir($dirlist)) !== false) { if(!is_dir($file)) { $files[] = $file; } } ($sortorder == 0) ? asort($files) : rsort($files); // arsort was replaced with rsort return $files; } else { return FALSE; break; } }}?>[/code][/quote]This returns me nothing .. I also set $dir = getcwd() Quote Link to comment https://forums.phpfreaks.com/topic/29591-cannot-go-into-a-subdirectory/#findComment-135802 Share on other sites More sharing options...
electronish Posted December 6, 2006 Author Share Posted December 6, 2006 plzz help Quote Link to comment https://forums.phpfreaks.com/topic/29591-cannot-go-into-a-subdirectory/#findComment-135819 Share on other sites More sharing options...
electronish Posted December 6, 2006 Author Share Posted December 6, 2006 [quote author=electronish link=topic=117494.msg479424#msg479424 date=1165366559]plzz help[/quote]Tried many things . . doesn't work .. Plz help .......... Quote Link to comment https://forums.phpfreaks.com/topic/29591-cannot-go-into-a-subdirectory/#findComment-135825 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.