|
|
|
|
![]() ![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 302 Joined: 17-June 05 From: Frankfurt, Germany Member No.: 8,358 |
Post
#1
May 21 2006, 08:23 PM
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: CODE $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? |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [MODERATOR]
Posts: 4,903 Joined: 24-July 05 From: Linux, DOS and Windows…the good, the bad and the ugly Member No.: 9,787 ![]() myCENT:81.50 |
Post
#2
May 21 2006, 08:43 PM
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.
|
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 302 Joined: 17-June 05 From: Frankfurt, Germany Member No.: 8,358 |
|
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [MODERATOR]
Posts: 4,903 Joined: 24-July 05 From: Linux, DOS and Windows…the good, the bad and the ugly Member No.: 9,787 ![]() myCENT:81.50 |
Post
#4
May 22 2006, 02:51 PM
Is it acceptable that you have to tell the script which sub-diectories to list the contents of?
|
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 302 Joined: 17-June 05 From: Frankfurt, Germany Member No.: 8,358 |
Post
#5
May 22 2006, 04:07 PM
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. |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [MODERATOR]
Posts: 4,903 Joined: 24-July 05 From: Linux, DOS and Windows…the good, the bad and the ugly Member No.: 9,787 ![]() myCENT:81.50 |
Post
#6
May 22 2006, 04:20 PM
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.
|
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 302 Joined: 17-June 05 From: Frankfurt, Germany Member No.: 8,358 |
|
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Post
#8
May 23 2006, 04:59 AM
hi, sxyloverboy, I have found this in www.php.net. It should be your need. Credit : msh at onliners dot dk CODE 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. |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 302 Joined: 17-June 05 From: Frankfurt, Germany Member No.: 8,358 |
Post
#9
May 24 2006, 04:15 PM
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/, pics dont know what else i could try but ive come to the conclusion that this script is faulty |
![]() ![]() |
Similar Topics
| Topic Title | Replies | Topic Starter | Views | Last Action | |||
|---|---|---|---|---|---|---|---|
![]() |
19 | KansukeKojima | 3,332 | 14th June 2009 - 05:27 PM Last post by: k_nitin_r |
|||
![]() |
4 | zip_mc | 13,280 | 22nd September 2009 - 10:26 AM Last post by: akira550 |
|||
![]() |
4 | LuciferStar | 7,604 | 19th August 2004 - 01:39 AM Last post by: LuciferStar |
|||
![]() |
2 | threepach | 2,092 | 19th February 2008 - 08:30 PM Last post by: threepach |
|||
![]() |
27 | OpaQue | 25,238 | 18th October 2007 - 05:33 AM Last post by: rvalkass |
|||
![]() |
2 | reconraiders | 1,810 | 1st October 2007 - 03:31 PM Last post by: ivenms |
|||
![]() |
3 | Zenchi | 4,856 | 13th October 2004 - 03:36 PM Last post by: ElBandoneonWEbsite |
|||
![]() |
3 | X3r0X | 4,652 | 1st October 2004 - 08:16 AM Last post by: X3r0X |
|||
![]() |
1 | hansley | 7,676 | 11th October 2004 - 03:54 AM Last post by: Trystim |
|||
![]() |
13 | Lyon | 5,376 | 8th April 2009 - 07:21 PM Last post by: Lyon2 |
|||
![]() |
10 | odomike | 7,434 | 10th February 2005 - 08:22 PM Last post by: round |
|||
![]() |
20 | sargilla | 10,664 | 1st November 2009 - 11:36 PM Last post by: Soviet Rathe |
|||
![]() |
0 | twoq | 4,314 | 7th November 2004 - 06:19 AM Last post by: twoq |
|||
![]() |
11 | Albus Dumbledore | 3,883 | 28th April 2009 - 02:28 PM Last post by: iG-Voffkin |
|||
![]() |
13 | Lyon | 3,120 | 1st November 2009 - 07:34 PM Last post by: Soviet Rathe |
|||
|
Open Discussion | Time is now: 6th November 2009 - 09:38 PM |
Web Hosting Powered by ComputingHost.com.