![]() |
List Directories, not files
Hello all,
Great website here. I hope I can share and help here, as well as get help as I learn... :-P I am trying to list just the directories under a certain folder. I don't want the files, just directories. Currently I have this: PHP Code:
PHP Code:
Thanks! |
Personally I'd do it this way:
PHP Code:
|
Thanks for the reply. However, I would like to just display the Directory Name, not with ../categories/ in front of it. I found if I do:
PHP Code:
|
I'd suggest using the is_dir() function in your while() loop.
Eg: PHP Code:
Note: '.' and '..' are considered directories so you might want to strip them as well :-) Alan. |
How about something such as the following. You could use regular expressions, but a normal string replace is much faster in this case.
php Code:
|
Thanks Wildhoney. That's nice and small and quick.
I am in the process of creating a flatfile cms of a sort for an intranet that has no access to a database, well I guess there is an Oracle db, but I don't understand how to use it... no one knows... I am trying to create a post function that will allow users to post information under directories. That is why I am trying to get just the directories. Thanks! |
Assuming your PHP build supports it, you coud always use SQLite instead - a ready to go database server built in to PHP :-)
More details: TalkPHP - Introduction to SQLite (yes, blatent self-promotion :-D) Alan |
How about:
PHP Code:
GLOB_ONLYDIR as in Wildhoney's example to grab the paths to directories within ../categories, then grab only the directory name (using basename()), before outputting the option HTML element. Aside: Note the use of commas to separate expressions for the |
No php5... someday they MIGHT update. Salathe... even less code! This is great. I went from 168 to 121 characters.
Have any of you used Gladius? Or FFDB? |
Quote:
Haven't seen/heard-of FFDB so ... nope. Gladius, heard of it by vague reference. |
Salathe: I just noticed that when I link to the $dir that is passed, I get only the first word in the directory. How do I go about making sure there are no spaces, and if there is, filling it with a _ when new directories are created from my form?
PHP Code:
|
PHP Code:
|
Quote:
|
Quote:
|
Aaron,
I'm not sure, but even if it is the implementation is a binary executable or library bound into PHP, and our scripts are just data and exempt. (WHEW!) If it gets linked into (compiled) or bound into your application you must use the GPL too. Reference this part of the FAQ plus the following two sections. This one is ugly too. And this, and the one immediately after. Unfortunately there is no end to this. So, it's just a lot simpler to avoid all GPL'ed code for non-GPL projects. No headaches that way. |
|
Quote:
|
Hey i just had to put my little contribution to the tread.
I borrowed some of WildHoneys code (sorry about that :) ). php Code:
My hopes is that going this way the lenght of the path would be recognized and cut of from the $dir variable. ;-) I was unsure about the last two parameters in substr() at time of writing this quickly, but i think you get the idea. /EyeDentify |
Additional
All,
I entered thread, addressing similar item at: http://www.talkphp.com/advanced-php-...ath-issue.html I have to have the mvc class popup object that shows the dialog with folders showing as icons, for my solution. How would you handle that? Thanks! OMR |
Nike Free 3.0 Shoes barefoot series of running shoes is one of the last couple of years, most the Nike fans favorite Nike Free 3.0 V4 running shoes.The series generally forefoot Waffle husband outside shading road design, has raised friction block has extremely suitable for running grip, and can be dispersed impact, make running more comfortable. The heel BRS1000 carbon fiber rubber, more wear-resistant, good grip, but the intense friction will leave a black mark on the ground.If Nike Free 3.0 Womens flexibility rating, 0.0 for barefoot running, 5.0 for ordinary running shoes. Nike Free Run Shoes running shoes introduced a FREE 3.0, Nike Free 3.0 V3 , FREE 7.0 FREE EVERYDAY FREE RUN + FREE style.nikefree30shoessale130313
|
| All times are GMT. The time now is 08:57 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0