Forum Moderators: coopster

Message Too Old, No Replies

Checking a directory

directory checking

         

Matthew1980

5:41 pm on Jun 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there people of webmaster world!

I know how to use file_exists() etc, is there a similar function for checking if a directory exists & if it holds value, I thought it would be dir_exists(), but not so, would it be is_dir(), im just a little confused.

Thanks,

Cheers,

Matthew

coopster

5:47 pm on Jun 19, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The PHP manual pages often have a See Also area that contains relative manual pages.

Use a combination of file_exists [php.net] and is_file [php.net].

Matthew1980

5:53 pm on Jun 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Coopster,

Yes I have just been looking through it, hence being confused, thanks for the pointer anywho.

Im just trying to improve an existing function that I have already written.

Cheers,

Matthew

coopster

6:05 pm on Jun 19, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I'm sorry, I think I misunderstood you. You can use is_dir [php.net] to determine if the filename (directory name) exists and is a directory. It will return TRUE if both conditions are met, FALSE otherwise.

Matthew1980

7:38 pm on Jun 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Coospter,

Thank you for adding that! I will now try that to see if it will help me in my new & improved function! Watch this space.

Thanks,

Matthew

dreamcatcher

8:13 pm on Jun 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you are running PHP5, a useful function to check the contents of a directory is scandir [us3.php.net]. That quickly reads directory contents into an array.

dc