<p>You can find the id in the database in the <code>craft_assetfolders</code> table. Creating a field with <em>uploads restricted to a single folder</em> does not create an asset folder. The asset folder only gets created when you actually have an asset in that folder, so before that point there is no <code>id</code>.</p>

CC BY-SA 3.0
2014-07-19T18:50:34.863Z
Thanks for the answer Marion, it does seem there's no simple way within the CP without resorting to querying the db then. Not a problem though.
John Moylan
CC BY-SA 3.0
2014-07-18T17:49:36.543Z
2014-07-18T17:49:36.543Z
Marion Newlevant
<p>Another approach is to inspect the sidebar element in the control panel using your browser. The screenshot below shows a <em>media</em> folder (id 9) that’s nested under a parent folder (id 1)</p>

<p><a href="https://i.sstatic.net/xngS3.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/xngS3.png" alt="screenshot of the CP sidebar’s folder element"></a></p>

CC BY-SA 3.0
2018-03-22T19:03:13.577Z
2018-03-22T19:03:13.577Z
Stephen Bowling
<p>You can do it like that     </p>

<pre><code>// return an associative array with the asset source handle as key
$assetSources = craft()-&gt;assetSources-&gt;getPublicSources('handle');
$assetSource = $assetSources['yourAssetSrcHandle'];
$assetFolder = craft()-&gt;assets-&gt;getRootFolderBySourceId($assetSource-&gt;id);
$assetFolder-&gt;id;
</code></pre>

<p>I also find weird that there is no direct method to get this from an asset source handle...</p>

CC BY-SA 3.0
2018-03-22T18:55:33.463Z
2018-03-22T18:55:33.463Z
Thomas Joeisseint
<p>Checkout the <a href="https://github.com/bjerenec/craftcms-blueprint/" rel="nofollow">blueprint</a> plugin. It doesn't currently do this, but it does similar things.</p>

CC BY-SA 3.0
2014-07-19T18:57:17.823Z
2014-07-19T18:57:17.823Z
Marion Newlevant
<p>I'm iterating through a folder using craft.assets, to select the folder I'll use the folderId.</p>

<p>What's the best way to find the folderId of a specific folder?</p>

<p>The only way I've found is to go the the Asset Settings page in the CP and hovering over a folder to see the url in the status bar in my browser.</p>

<p><strong>Related Problem:</strong></p>

<p>I created a folder in the CP Fields page (see image) and there seems no way to get this folderId as I cannot get to it in the Asset Settings page. As I only have a small number of folders I was able to figure it but it got me wondering if I was missing the obvious somewhere?</p>

<p>Thanks</p>

<p>John</p>

<p><img src="https://i.sstatic.net/4LdAs.png" alt="Folder added in Field page"></p>

<assets>
Best way to find a folderId
# Best way to find a folderId

(Asked by: username_0 on 2014-07-18)

I'm iterating through a folder using craft.assets, to select the folder I'll use the folderId.

What's the best way to find the folderId of a specific folder?

The only way I've found is to go the the Asset Settings page in the CP and hovering over a folder to see the url in the status bar in my browser.

**Related Problem:**

I created a folder in the CP Fields page (see image) and there seems no way to get this folderId as I cannot get to it in the Asset Settings page. As I only have a small number of folders I was able to figure it but it got me wondering if I was missing the obvious somewhere?

Thanks

John

![Folder added in Field page](https://i.sstatic.net/4LdAs.png)

**Tags:** assets


---

## 4 answers

### Answer by username_1 on 2014-07-18. Score: 2 | Accepted answer

You can find the id in the database in the `craft_assetfolders` table. Creating a field with *uploads restricted to a single folder* does not create an asset folder. The asset folder only gets created when you actually have an asset in that folder, so before that point there is no `id`.

> **Comments:**
> **username_0**: Thanks for the answer Marion, it does seem there's no simple way within the CP without resorting to querying the db then. Not a problem though.  

---

### Answer by username_2 on 2018-03-22. Score: 2

Another approach is to inspect the sidebar element in the control panel using your browser. The screenshot below shows a *media* folder (id 9) that’s nested under a parent folder (id 1)

[![screenshot of the CP sidebar’s folder element](https://i.sstatic.net/xngS3.png)](https://i.sstatic.net/xngS3.png)


---

### Answer by username_3 on 2018-03-22. Score: 2

You can do it like that     
// return an associative array with the asset source handle as key
$assetSources = craft()->assetSources->getPublicSources('handle');
$assetSource = $assetSources['yourAssetSrcHandle'];
$assetFolder = craft()->assets->getRootFolderBySourceId($assetSource->id);
$assetFolder->id;

I also find weird that there is no direct method to get this from an asset source handle...


---

### Answer by username_1 on 2014-07-19. Score: 1

Checkout the [blueprint](https://github.com/bjerenec/craftcms-blueprint/) plugin. It doesn't currently do this, but it does similar things.


---

