Count the number of files in directory and all sub directories

I had a search around and could not find a solution, i saw the count and total files but do not think its suitable.

Looking to sum the number of music files in a directory and all sub directories (there will be sub directories for different cds so the tracks are not going to be a run of numbers)

I want to divide my box set albums into folders that have 1001+, 501-1000, 251-500, 101-250, 51-100, 26-50, 1-25 tracks

X:\Music\Collection\Box Sets (1001+)\ABC of the Blues\B.B. King
X:\Music\Collection\Box Sets (1001+)\ABC of the Blues\Bukka White & Josh White

I can sort the logic for creating the tag - filename but have no clue how to get the number of tracks.

I would prefer to get a script to do all the boxsets already there, going forward i can tag it as i go.

Any ideas? Or suggestions what to look at?

I don't think that this is possible in Mp3tag, because Mp3tag knows nothing about a "Box Set".
It cannot distinguish between folders containing artists, folders containing albums, and folders containing "Box Sets".

I would recommend to use an external tool like TreeSize Free (free for private use) to search for your "Box Sets" manually and see the number of Folders and Files.

Example screen:

thanks for your help,

there is only 1 level that needs to be done - the directory Box Sets, so i want each of those folders to count all the files in sub directories and add it to a tag in the filenames. So 100% Blues Ballads & Slow Blues will count all 5 of the sub directories.

i was thinking of using advanced renamer, for the existing ones, used that for years, i'll rename the folders in the boxset directory with ((number of files)) then filename - tag

Going forward an action with %_total_files% will work ok, when im doing the rest of the tagging and have all the files in the box set selected.

Was just wondering if it can be done.

You could use the track numbering wizard and use the _DIRECTORY as reset criterium for the track counter.
Store the number of total files also, then use that piece of information to rename the folder.
Please note that this counter will only add up the number of files supported by MP3tag. Any baggage files will not be counted.

I do not want to actually renumber the tracks, been using the auto numbering wizard, its a great little tool with loads of options, is there an option to not write to the track number tag? just get the total number (if that makes sense)

friday evening and i've had a few glasses of wine so im not going near my collection at this point, not even a test folder, i'll end up pressing the wrong thing

TBH i was just wondering if there was an easy way to cycle through the folders already in my collection, if not, its easy to use another program to create the number in the file path and then use mp3tag to get that number back out, all really quick, and total files is really quick to add the tag when im importing new stuff.

No. But you could store the current track numbers in a user-defined field (with an action), get the total number with the numbering wizard, modify the folder name and then get the track numbers back from the user-defined field.

I tested this on my system with the same folder structure and it works great.

I assume you’re using Windows.

Run Windows PowerShell (Right click on start menu)

Then copy & paste this in and hit enter.

$root  = "X:\Music\Collection\Box Sets"
$exts  = @("flac","mp3","wav","aac","ogg","m4a")

Get-ChildItem -LiteralPath $root -Directory | ForEach-Object {
    $folder = $_.FullName

    # Grab all files recursively from this folder
    $files = Get-ChildItem -LiteralPath $folder -Recurse -File | Where-Object { $exts -contains $_.Extension.TrimStart('.') }

    # Count by extension
    $counts = @{}
    foreach ($ext in $exts) {
        $counts[$ext] = ($files | Where-Object { $_.Extension -ieq ".$ext" }).Count
    }

    [PSCustomObject]@{
        Folder = $_.Name
        Path   = $folder
        FLAC   = $counts["flac"]
        MP3    = $counts["mp3"]
        WAV    = $counts["wav"]
        AAC    = $counts["aac"]
        OGG    = $counts["ogg"]
        M4A    = $counts["m4a"]
        Total  = $files.Count
    }
} | Format-Table -AutoSize

The output I got from my test was:

Folder                                                                                                                           Path                                                                                                                                                          FLAC MP3 WAV AAC OGG M4A Total
------                                                                                                                           ----                                                                                                                                                          ---- --- --- --- --- --- -----
Def Leppard - 2018 - CD Collection- Volume One Box Set {2018 7CD Limited Edition Remaster, UMC, 02557773583} [CD - FLAC - 16-44] X:\Music\Collection\Box Sets\Def Leppard - 2018 - CD Collection- Volume One Box Set {2018 7CD Limited Edition Remaster, UMC, 02557773583} [CD - FLAC - 16-44]    7   0   0   0   0   0     7
Def Leppard - 2019 - CD Collection Volume 2 7CD {2019 Remaster, UMC, 00602567313922} [CD - FLAC - 16-44]                         X:\Music\Collection\Box Sets\Def Leppard - 2019 - CD Collection Volume 2 7CD {2019 Remaster, UMC, 00602567313922} [CD - FLAC - 16-44]                            7   0   0   0   0   0     7
Kiss - 2012 - The Casablanca Singles 1974-1982 Box Set {B0017192-21} (VH 2020) [Vinyl - FLAC - 24-96]                            X:\Music\Collection\Box Sets\Kiss - 2012 - The Casablanca Singles 1974-1982 Box Set {B0017192-21} (VH 2020) [Vinyl - FLAC - 24-96]                              58   0   0   0   0   0    58

Thanks for all the suggestions, I spent a bit of time today looking at the ideas and couldn't quite work out the solution.

So just did it manually, this stuff doesn't come easy to me, if I spent hours I might be able to work it out, and I do try to, but it took 20 minutes to do manually.

Thanks for all your help.