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 Quote 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"); } ?> Quote 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. Quote 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 Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.