<p>Seems doable with a custom <a href="https://pluginfactory.io" rel="nofollow noreferrer">plugin</a>.</p>

<p>The pseudo-code would be something like:</p>

<ol>
<li>Use <a href="https://craftcms.com/classreference/services/AssetsService" rel="nofollow noreferrer">AssetsService</a> to grab all of the files for the source.</li>
<li>Loop through the files and parse the parent folder paths.</li>
<li>Based on the subfolder for the asset, check if an existing tag already exists with the <a href="https://craftcms.com/classreference/services/TagsService" rel="nofollow noreferrer">TagsService</a>.</li>
<li>If 3 is true, assign that tag's value to a tag field on the Asset.</li>
<li>If 3 is false, create the tag using the TagsService, then assign that tag's value to a tag field on the Asset.</li>
</ol>

CC BY-SA 3.0
2017-02-14T20:10:41.417Z
2017-02-14T20:10:41.417Z
Brad Bell
<p>I'm building a project with a lot of photo assets organized into sub directories of the main photos asset source. I'm trying to add tags to these assets so they are searchable when I try to use them in my entries.</p>

<p>With native features of Craft, this process seems to be very manual, I just have to click on each of these asset files and add the tags that I want.</p>

<p>Is there a way, either using a plugin or make a MySQL query, to bulk add tags to all the asset files under a certain sub directory?</p>

CC BY-SA 3.0
2017-02-10T22:01:29.550Z
Are the tags based on the subfolder name or something?  Or are they going to be more dynamic regardless of what folder they live in?
Brad Bell
CC BY-SA 3.0
2017-02-14T00:12:43.017Z
The tags are supposed to be the same as the subfolder names.
ChaiTea
<assets><plugins><tags><mysql><subfolder>
Tagging all assets in a sub directory
# Tagging all assets in a sub directory

(Asked by: username_0 on 2017-02-10)

I'm building a project with a lot of photo assets organized into sub directories of the main photos asset source. I'm trying to add tags to these assets so they are searchable when I try to use them in my entries.

With native features of Craft, this process seems to be very manual, I just have to click on each of these asset files and add the tags that I want.

Is there a way, either using a plugin or make a MySQL query, to bulk add tags to all the asset files under a certain sub directory?

**Tags:** assets, plugins, tags, mysql, subfolder
> **Comments:**
> **username_1**: Are the tags based on the subfolder name or something?  Or are they going to be more dynamic regardless of what folder they live in?  
> **username_0**: The tags are supposed to be the same as the subfolder names.  

---

## 1 answers

### Answer by username_1 on 2017-02-14. Score: 1

Seems doable with a custom [plugin](https://pluginfactory.io).

The pseudo-code would be something like:

1. Use [AssetsService](https://craftcms.com/classreference/services/AssetsService) to grab all of the files for the source.
2. Loop through the files and parse the parent folder paths.
3. Based on the subfolder for the asset, check if an existing tag already exists with the [TagsService](https://craftcms.com/classreference/services/TagsService).
4. If 3 is true, assign that tag's value to a tag field on the Asset.
5. If 3 is false, create the tag using the TagsService, then assign that tag's value to a tag field on the Asset.


---

