Calculate & Store Folder Size

I saw this question posted on the forums a while back and it didn't get a response so I went about this on my own. There is probably a way to do this more efficiently by piggy-backing the action to the export but I haven't gotten that far yet. This will work to calculate the size of a folder which I used to delete probably duplicates in my collection.

Background: I had 300,000 files with multiple duplicates because I mis-configured my backup. Files were stored in the following format...

2016.11 Backup\Alkaline Trio\Good Mourning

                                       \This Addiction
                                        \From Here To Infirmary

2016.10 Backup\Alkaline Trio\Good Mourning

                                       \My Shame Is True

2016.09 Backup\Alkaline Trio\My Shame Is True


Not all files and folders were setup this pretty but for the most part I had at least Artist, Album, Track information for all the files.

To merge all the source files and folders while deleting exact duplicates I needed to create a unique identifier for the folders. I settled on three data points; number of files, size of folder, total playing time of files in folder.

First, add a new custom column to your list view, I called mine New Path and named the variable %new_path%. I'm crazy creative. :rolleyes:

Next, create a new Export by clicking on File->Export and clicking on the 'New' button. Name it whatever. Your default text editor will open with a basic template. Delete all the text in the template and replace it with the following:

$filename(path.txt,utf-8)$loop(%_folderpath%,1)$loopend()(%_total_files% TR - %_total_size% - %_total_time%)

This script will create a file called path.txt in each specified folder containing the information we want.

Change the path.txt and/or utf encoding to whatever you wish or just leave it as is. Close the file, saving it, and go back to MP3Tag.

Click on Actions->Actions and create a new action. Name it whatever and in the new actions window add a new action type. From the drop-down select 'Import text file' and click 'Ok'. Click on the drop-down for 'Field' and select the variable you created earlier, for me it was NEW_PATH. For the 'Filename' input, paste your derivative of the following:


Click 'Ok' to close the 'Action Edit' menu. 'Ok' again, then again. You should be at the MP3Tag main window.

To run the script/action:

First run the export to create the file. File->Export (select your new export)
Next run the action. Actions->Your Custom Action
You will see your new calculated value in the columns under the name you provided.

To use this info to purge duplicates and make selective deleting easier convert the tags to filenames. I used the following string...

D:\Merged Music\\%artist%\\%album% - $validate(%new_path%,.)\$num(%track%,2) - %title%

You will get a message after the rename that existing files could not be replaced. This is a good thing, that means that duplicate files were found and are not being overwritten. If you are concerned that the 3 qualifiers I used would leave you open to overwriting good files add an MD5 or CRC hash to the export but I didn't find that necessary.

The folders that are created will be in the following format:

..\My Shame Is True - (12 TR - 80.76 MB - 00.40.01)
..\My Shame Is True - (14 TR - 90.29 MB - 00.44.58)
..\My Shame Is True Vinyl - (12 TR - 74.95 MB - 00.36.28)

Simply remove the smaller folder or the one with fewer tracks or keep them both. Change the export string to use information like bitrate, encoding or whatever helps you choose the preferable files to keep.

Enjoy, and please donate for the use of the program, I did.