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.
determin what is a folder and what is not?
Moderators: egami, macek, gesf
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.
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;
}
}
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?
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