Title: Loop through multiple folders
Last modified: August 30, 2016

---

# Loop through multiple folders

 *  [cristofayre](https://wordpress.org/support/users/cristofayre/)
 * (@cristofayre)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/loop-through-multiple-folders/)
 * I have 25 directories, so to transfer each one, I currently:
    1) Set the base
   path 2) Set the category to upload files to 3) Save settings 4) Import files
 * Thus, it takes around 30 ~ 40 mins to update all the folders. And this has to
   be done weekly!
 * I’m wondering if it might be possible to amend the PHP such that it reads a main
   folder, and auto sets the path / categories
 * For example, I have:
 * Found_files/
    Set1/ Set2/ … .. Set25/
 * Would it be possible to set the absolute path to “[http://my-server/found_files&#8221](http://my-server/found_files&#8221);,
   and for the script to then reiterate through the folder, setting its own base
   path:
    [http://my-server/found_files/Set1](http://my-server/found_files/Set1)
   [http://my-server/found_files/Set2](http://my-server/found_files/Set2) [http://my-server/found_files/Set25](http://my-server/found_files/Set25)
 * The HTML within would be transferred to categories “Set1”, “Set2”, “Set25” etc
   within WordPress.
 * ** Just spent the morning “pulling out” the fields on the option page, and the
   form code that submits the “Import” button. My idea was that I could create a
   program that would read the main directory, (such as OpenDir / ReadDir) create
   a form with all the fields set dynamically, (such as html_import[root_directory]
   updated on each loop) and submit to save settings each time, then run the IMPORT
   form to complete the process.
 * Now some values are set to ” ” whilst others only appear when an <div> option
   is chosen. Can’t work out if I need to submit ALL the fields – even if empty –
   or what are the minimum required fields.
    (I am saving as “pending” with title
   set from filename: Only two options set, no Dreamweaver or HTML tags etc) And
   no idea at all what “_wpnonce” or “_wp_http_referer” does!!
 * So before I spend 3 – 4 days trying to build a work around, I thought I’d check
   whether a solution already exists
 * [https://wordpress.org/plugins/import-html-pages/](https://wordpress.org/plugins/import-html-pages/)

The topic ‘Loop through multiple folders’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/import-html-pages.svg)
 * [HTML Import 2](https://wordpress.org/plugins/import-html-pages/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/import-html-pages/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/import-html-pages/)
 * [Active Topics](https://wordpress.org/support/plugin/import-html-pages/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/import-html-pages/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/import-html-pages/reviews/)

## Tags

 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [root folder](https://wordpress.org/support/topic-tag/root-folder/)

 * 0 replies
 * 1 participant
 * Last reply from: [cristofayre](https://wordpress.org/support/users/cristofayre/)
 * Last activity: [10 years, 9 months ago](https://wordpress.org/support/topic/loop-through-multiple-folders/)
 * Status: not resolved