# Count number of folders in parent directory?

**URL:** https://community.mp3tag.de/t/count-number-of-folders-in-parent-directory/16962
**Category:** Support
**Created:** [June 12, 2015, 11:17pm UTC](https://community.mp3tag.de/t/count-number-of-folders-in-parent-directory/16962 "2015-06-12T23:17:10Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![theG](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/t/977dab/32.png) [@theG](https://community.mp3tag.de/u/theG)
#### Post date: [June 12, 2015, 11:17pm UTC](https://community.mp3tag.de/t/count-number-of-folders-in-parent-directory/16962/1 "2015-06-12T23:17:10Z")

</div>

My folder structure is as follow:

...**\</b\>Artist 1\</b\>Artist 1 - Album 1\</b\>  
...\</b\>Artist 1\</b\>Artist 1 - Album 2\</b\>  
...\</b\>Artist 1\</b\>Artist 1 - Album 3\</b\>Disc 01\</b\>  
...\</b\>Artist 1\</b\>Artist 1 - Album 3\</b\>Disc 02\</b\>  
...\</b\>Artist 1\</b\>Artist 1 - Album 3\</b\>Disc 03\</b\>  
...\</b\>Artist 1\</b\>Artist 1 - Album 4\</b\>  
etc..**

Is there a way to count the number of folders present in the parent directory?  
Something like:  
**$if($eql($left(%\_directory%,5),Disc ),**_[COUNT # OF FOLDERS IN PARENT & SET TOTALDISCS]_ **,** _[SET TOTALDISCS TO 1]_**)**

---

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [June 13, 2015, 5:47am UTC](https://community.mp3tag.de/t/count-number-of-folders-in-parent-directory/16962/2 "2015-06-13T05:47:07Z")

</div>

> [@Guillaume](#):
>
> ... Is there a way to count the number of folders present in the parent directory? ...

There is no proper way in the interactive interface of Mp3tag, but you may create an export script, which can count the folders, like this example script ...

**1: $filename($getEnv('USERPROFILE')'\Desktop\Mp3tag.Export.txt',UTF-8)** 

**2: $loop($folderdepth(%\_folderpath%))  
3: 'Folderdepth: '$folderdepth(%\_folderpath%)  
4: $loop(%\_directory%,1)  
5: %\_parent\_directory%'|'%\_directory%  
6: $loopend()  
7: 'Folder count: '%\_max\_counter%  
8: $loopend()  
9: 'Folderpath count: '%\_max\_counter%**

 

DD.20150613.0947.CEST

 

You may check out the method there ...  
[/t/12767/1](https://community.mp3tag.de/t/12767/1)

 

DD.20150613.1033.CEST

---

<div class="post-metadata">

### Author: ![theG](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/t/977dab/32.png) [@theG](https://community.mp3tag.de/u/theG)
#### Post date: [June 13, 2015, 4:56pm UTC](https://community.mp3tag.de/t/count-number-of-folders-in-parent-directory/16962/3 "2015-06-13T16:56:24Z")

</div>

I was hoping to find a way so I can use it with Action -\> Format Value since I need it to to set the TOTALDISCS tag. Exporting to a text file is pretty useless for what I want to achieve. ![<_<](https://community.mp3tag.de/uploads/default/original/1X/5996dbb474c88b8f9fc49f09dc3858d081055a2d.gif "<\_<")

---

<div class="post-metadata">

### Author: ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)
#### Post date: [June 13, 2015, 5:05pm UTC](https://community.mp3tag.de/t/count-number-of-folders-in-parent-directory/16962/4 "2015-06-13T17:05:42Z")

</div>

> [@Guillaume](#):
>
> ... pretty useless ...

Harsh words.  
I assume that you do know the action "Import data from text file"?  
If you store the totaldiscs in a text file, you can easily retrieve it from there and import it to the selected files.  
Reconsider "useless".

---

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [June 13, 2015, 5:07pm UTC](https://community.mp3tag.de/t/count-number-of-folders-in-parent-directory/16962/5 "2015-06-13T17:07:48Z")

</div>

> [@Guillaume](#):
>
> I was hoping to find a way so I can use it with Action -\> Format Value since I need it to to set the TOTALDISCS tag. Exporting to a text file is pretty useless for what I want to achieve. ![<_<](https://community.mp3tag.de/uploads/default/original/1X/5996dbb474c88b8f9fc49f09dc3858d081055a2d.gif "<\_<")

You can do it as a 2-step method by using 2 actiongroups.  
Step 1. Export the calculated or cumulated data via report output to text file.  
Step 2. Import the data from the text file into the related tag-fields.

DD.20150613.2107.CEST

---

<div class="post-metadata">

### Author: ![system](https://community.mp3tag.de/uploads/default/original/2X/c/ce7035d426cb755a7916793326d23b465222a407.png) [@system](https://community.mp3tag.de/u/system)
#### Post date: [February 9, 2026, 12:25pm UTC](https://community.mp3tag.de/t/count-number-of-folders-in-parent-directory/16962/6 "2026-02-09T12:25:42Z")

</div>


