title: Wordpress > getting full path to my theme's images directory regardless of parent paths
body: <p>I have a function whose purpose is to list the folders within the images directory of my wordpress theme. It works great when the user has installed wordpress in the root directory of the site. However, it fails if the user has installed wordpress in a folder under the root...</p>
  
  <p>$mydir = get_dirs($_SERVER['DOCUMENT_ROOT'].'/wp-content/themes/mytheme/images');</p>
  
  <p>This function works fine as long as the wordpress is installed directly into the site's root, such as site.com/index.php</p>
  
  <p>However, this path method fails, if the user has installed their blog in a virtual directory. Example: site.com/somedirectory/index.php</p>
  
  <p>Can someone help with a better method of determining the path of the $mydir?</p>
  
  <p>It would be super simple if I could feed my function with the http address, but my function requires the path to the images directory as a server directory. Anyone know of a way to find the folders under a given directory using the http method instead? For example, I can get a reference to my theme's images directory with...</p>
  
  <p>$mydir = get_bloginfo('url').'/wp-content/themes/mytheme/images';</p>
  
  <p>However, the function below, will not take a URL, it must be a physical file path to the chosen directory I want to parse. So I either need to replace it with a function that takes a URL or I need to find some way to convert the $mydir function to a physical path, or perhaps some other means.</p>
  
  <p>Here is the function that I'm using for parsing the directory and assigning each folder to an array.</p>
  
  <pre><code>function get_dirs($path = '.') 
  {
  $dirs = array();
  try
  {
      foreach (new DirectoryIterator($path) as $file) 
      {
          if ($file-&gt;isDir() &amp;&amp; !$file-&gt;isDot()) 
          {
          $dirs[] = $file-&gt;getFilename();
          }
      }
  } 
  catch(Exception $e) 
  {
      //log exception or process silently
      //just for test
      echo "There is a problem inside the get_dirs function";
  }
  return $dirs;
  }
  </code></pre>