cgm225 Posted February 7, 2008 Share Posted February 7, 2008 I want to create an array of subdirectories within a root directory, that does not contain any file names, and is nonrecursive Any ideas? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/89933-create-array-of-subdirectories-no-files-nonrecursive/ Share on other sites More sharing options...
trq Posted February 7, 2008 Share Posted February 7, 2008 I'm ure this probably isn't what your after, but its how I read your post. <?php $subdirs = array('foo','bar','meh'); foreach($subdirs as $dir) { mkdir("root/$dir"); } ?> Link to comment https://forums.phpfreaks.com/topic/89933-create-array-of-subdirectories-no-files-nonrecursive/#findComment-461039 Share on other sites More sharing options...
cgm225 Posted February 7, 2008 Author Share Posted February 7, 2008 Sorry, I should clarify. I want to list directories that are already present within the root, but not the files, and I do not want a recursive listing. Link to comment https://forums.phpfreaks.com/topic/89933-create-array-of-subdirectories-no-files-nonrecursive/#findComment-461049 Share on other sites More sharing options...
cgm225 Posted February 7, 2008 Author Share Posted February 7, 2008 bump Link to comment https://forums.phpfreaks.com/topic/89933-create-array-of-subdirectories-no-files-nonrecursive/#findComment-461282 Share on other sites More sharing options...
kenrbnsn Posted February 8, 2008 Share Posted February 8, 2008 I would use the read_dir() function: <?php $dirs = array(); if ($handle = opendir('/path/to/directory')) { while (false !== ($file = readdir($handle))) { if (is_dir('/path/to/directory/' . $file) && $file != '.' && $file != '..') $dirs[] = $file; } closedir($handle); } echo '<pre>' . print_r($dirs,true) .'</pre>'; // just checking ?> Ken Link to comment https://forums.phpfreaks.com/topic/89933-create-array-of-subdirectories-no-files-nonrecursive/#findComment-461350 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.