stickman Posted August 29, 2006 Share Posted August 29, 2006 For this question, I dont think its possible, but it doesnt hurt to ask does it? Anyway, I cant use any FTP function to do this because they only retrieve the first 1000 files and I need it to retrive all of the files which is more than 1000. I also cant use any loops or it will take like 10 mintues to execute. So with these restrictions, is it possible to retrieve an array with all the filenames (in subdirectory/filename.extension format) within subdirectories. This is what I have currently:[code]<?php$data = "";exec("ls */", $data);print_r($data);?>[/code]The problems with that is it doesnt include the subdirectory name, for example (subdir1/file.txt and subdir2/file.txt). Thanks in advance for any help that you can offer. Link to comment https://forums.phpfreaks.com/topic/18971-retrieve-all-files-in-subdirectories/ Share on other sites More sharing options...
stickman Posted August 29, 2006 Author Share Posted August 29, 2006 Nevermind my question. That returned the subdirectories name as its own array value and then I was able to convert that into a header in which all the filenames below it fall in that subdirectory. Therefore, that code answered my own question, except I had to do some various array things first. Link to comment https://forums.phpfreaks.com/topic/18971-retrieve-all-files-in-subdirectories/#findComment-82010 Share on other sites More sharing options...
SharkBait Posted August 29, 2006 Share Posted August 29, 2006 Another way to do it would be readdir()Here is the example from php.net[code]<?phpif ($handle = opendir('.')) { while (false !== ($file = readdir($handle))) { // Strip out .. and . if ($file != "." && $file != "..") { echo "$file\n"; } } closedir($handle);}?> [/code] Link to comment https://forums.phpfreaks.com/topic/18971-retrieve-all-files-in-subdirectories/#findComment-82143 Share on other sites More sharing options...
Jenk Posted August 29, 2006 Share Posted August 29, 2006 Recursion..[code]<?phpfunction print_directories($dir, $return = false){ $dir = realpath($dir); $handle = opendir($dir); if (!$handle) return false; $output = ''; while (($file = readdir($handle)) !== false) { if ($file != '.' && $file != '..') { $output .= $dir . DIRECTORY_SEPARATOR . $file . "\n"; if (is_dir($dir . DIRECTORY_SEPARATOR . $file)) { $output .= print_directories($dir . DIRECTORY_SEPARATOR . $file, true); } } } if ($return) return $output; echo $output;}print_directories('.');?>[/code] Link to comment https://forums.phpfreaks.com/topic/18971-retrieve-all-files-in-subdirectories/#findComment-82162 Share on other sites More sharing options...
stickman Posted August 29, 2006 Author Share Posted August 29, 2006 [quote author=stickman link=topic=106025.msg423765#msg423765 date=1156820399]I also cant use any loops or it will take like 10 mintues to execute.[/quote]But thanks for the help. Link to comment https://forums.phpfreaks.com/topic/18971-retrieve-all-files-in-subdirectories/#findComment-82322 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.