determin what is a folder and what is not?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

User avatar
imroue
New php-forum User
New php-forum User
Posts: 62
Joined: Fri Oct 11, 2002 6:53 am
Contact:

determin what is a folder and what is not?

Postby imroue » Mon Oct 14, 2002 5:48 pm

i know there could be a long way of doing this.but maybe someone has a shorter way.
I would like to search a folder/directory and scan everything in it.. and return only the folders that are in (Basically ignore all files)
Maybe put these folders in an array or somehthing..
any ideas? I am not sure how to put them in an array.. so if you can suggest..that would be great also.

ednark
New php-forum User
New php-forum User
Posts: 18
Joined: Fri Oct 04, 2002 8:09 pm

Postby ednark » Mon Oct 14, 2002 6:18 pm

read more here:
http://www.php.net/manual/en/function.opendir.php
http://www.php.net/manual/en/function.readdir.php
http://www.php.net/manual/en/function.is-dir.php

here is some code that steps through a directory and makes a list of files and directories.

Code: Select all

        $path = 'path/to/dir/';
        $dir = opendir($path);

        while (($item = readdir($dir)) !== false) {
            $item_path = $path.$item;
            if ( is_dir($item_path) ) {
                if ( ($item != ".") and ($item != "..") ) {
                    $dirs[] = $item;
                }
          } else {
                    $files[] = $item;
          }
        }

User avatar
imroue
New php-forum User
New php-forum User
Posts: 62
Joined: Fri Oct 11, 2002 6:53 am
Contact:

Postby imroue » Mon Oct 14, 2002 6:56 pm

ednark wrote:read more here:
http://www.php.net/manual/en/function.opendir.php
http://www.php.net/manual/en/function.readdir.php
http://www.php.net/manual/en/function.is-dir.php

here is some code that steps through a directory and makes a list of files and directories.

Code: Select all

        $path = 'path/to/dir/';
        $dir = opendir($path);

        while (($item = readdir($dir)) !== false) {
            $item_path = $path.$item;
            if ( is_dir($item_path) ) {
                if ( ($item != ".") and ($item != "..") ) {
                    $dirs[] = $item;
                }
          } else {
                    $files[] = $item;
          }
        }


Thanks for the reply.. but i get an error on the arrays $dir[]...
is there any info on how to declare an array without specifying the number of items in the array? I guess i mean declaring the array dynamically?

Jay

Postby Jay » Tue Oct 15, 2002 5:44 am

imroue wrote:is there any info on how to declare an array without specifying the number of items in the array? I guess i mean declaring the array dynamically?

PHP does this already


Return to “PHP coding => General”

Who is online

Users browsing this forum: Bing [Bot] and 5 guests

cron