sxyloverboy 0 Report post Posted May 21, 2006 So lets say i have folders called friends and work in a folder called pics. how would i make a function that lists the files in those folderscalled images kinda like this: $directory = "./"function listfiles($directory) {//here should go the script to list the files in those directories. so that i can continue to work with them. like for example if there were images it would list all the images and i could write a script to make a thumb of them and then save it into a thumb folder(not asking for all of that). but how would i make it list it. // basicly what i need is a loop for the files and a echo that lists them. } the key point in my question is that it repects subdirectories. which is important forthe script i wanna make. any ideas? Share this post Link to post Share on other sites
jlhaslip 4 Report post Posted May 21, 2006 Do you want to "hard-code" the sub-directory names? or have the sub-drectories found by the script in that directory? Makes a difference to the scripting involved. Share this post Link to post Share on other sites
sxyloverboy 0 Report post Posted May 22, 2006 hmm..dont understand your question. ^^; Share this post Link to post Share on other sites
jlhaslip 4 Report post Posted May 22, 2006 Is it acceptable that you have to tell the script which sub-diectories to list the contents of? Share this post Link to post Share on other sites
sxyloverboy 0 Report post Posted May 22, 2006 hm i suppose i could do that myself with an array or? but what i want it to do automaticly. and thats what i cant do. i want it go through each of the folders where the script is run. and list the files. then look through the subfolders to see if theres any subfolders there ect. i hope this is not to hard to code. if it only works with one level of subfolders i suppose that would be ok too. Share this post Link to post Share on other sites
jlhaslip 4 Report post Posted May 22, 2006 There is a way to do that, and I thought I had a script for it, but I can't seem to find it. I'll keep looking for it. It is a recursive loop that does precisely what you want. Share this post Link to post Share on other sites
sxyloverboy 0 Report post Posted May 22, 2006 hm well id really appreciate if you found it. Share this post Link to post Share on other sites
magiccode9 0 Report post Posted May 23, 2006 hi, sxyloverboy, I have found this in http://php.net/. It should be your need.Credit : msh at onliners dot dk I would like to present these two simple functions for generating a complete directory listing - as I feel the other examples are to restrictive in terms of usage.function dirTree($dir) { $d = dir($dir); while (false !== ($entry = $d->read())) { if($entry != '.' && $entry != '..' && is_dir($dir.$entry)) $arDir[$entry] = dirTree($dir.$entry.'/'); } $d->close(); return $arDir;}function printTree($array, $level=0) { foreach($array as $key => $value) { echo "<div class='dir' style='width: ".($level*20)."px;'> </div>".$key."<br/>\n"; if(is_array($value)) printTree($value, $level+1); }}Usage is as simple as this:$dir = "<any directory you like>";$arDirTree = dirTree($dir);printTree($arDirTree);It is easy to add files to the tree also - so enjoy. Share this post Link to post Share on other sites
sxyloverboy 0 Report post Posted May 24, 2006 hm that one dosent really work. it just shows a line called array. and yes i made the directory name right i tried a number of possiblities/pics/, /pics, ./pics, ./, /, pics/, picsdont know what else i could try but ive come to the conclusion that this script is faulty Share this post Link to post Share on other sites