Export Config to Count Files for Each Podcast Category

The attached export config displays a count of files containing each podcast category (%podcastcategory%). It takes into account multi-value fields.
I use it to find spelling and other errors in the categories.
It's easy to modify for any other tags you may want to count.

Program logic:

  1. build a master file containing all categories (on the desktop)
  2. sort the file
  3. iterate through the file looking for changes one to the next and counting as you go

It leaves a couple of files on the desktop for you to clean up when you're done.

One nagging issue remains: it screws up if the field contains a pipe (|). I haven't figured out yet how to escape those darn pipes in the meta_sep operation.

Note: mostly not my coding. I merely modified some code found on stackoverflow

.mte coding is as follows ------------

$filename($getEnv('USERPROFILE')'\desktop\CategoryCounts.bat',ANSI)
@Echo Off
chcp 1254
if exist "%%USERPROFILE%%\Desktop\taglisting.txt" del "%%USERPROFILE%%\Desktop\taglisting.txt" /q
$loop(%podcastcategory%)
echo>>"%%USERPROFILE%%\Desktop\taglisting.txt" $meta_sep(podcastcategory,$char(13)$char(10)echo>>"%%USERPROFILE%%\Desktop\taglisting.txt" )
$loopend()
@echo off
setlocal disableDelayedExpansion
set "file=%%USERPROFILE%%\Desktop\taglisting.txt"
set "sorted=%%file%%.sorted"
set "counted=%%file%%.counted"
set /a N = 1
REM Define a variable containing a linefeed character
set LF=^

REM The 2 blank lines above are critical, do not remove
sort "%%file%%" >"%%sorted%%"

"%%counted%%" (
set "prev=start"
for /f usebackq^ eol^=^%%LF%%%%LF%%^ delims^= %%%%A in ("%%sorted%%") do (

set "curr=%%%%A"
setlocal enableDelayedExpansion
if /i "!curr!" neq "!prev!" (
if "!prev!" neq "start" echo !n!	!prev!

endlocal
  set "prev=%%%%A"
  set /a N = 1

) else (
endlocal
set /a N += 1
)

)

setlocal enableDelayedExpansion
echo !n!	!curr!
endlocal

)

nul move /y "%%counted%%" "%%file%%"
del "%%sorted%%"
"%%USERPROFILE%%\Desktop\taglisting.txt"

CategoryCounts.mte (1.19 KB)

Little bit slower but the following fixes the pipes (|) question I left above.

$filename($getEnv('USERPROFILE')'\desktop\TagCount.bat',ANSI)
@Echo Off
chcp 1254
if exist "%%USERPROFILE%%\Desktop\taglisting.txt" del "%%USERPROFILE%%\Desktop\taglisting.txt" /q
REM Creating a Newline variable (the two blank lines below are required!)
set NLM=^

set NL=^^^%%NLM%%%%NLM%%^%%NLM%%%%NLM%%
$loop(%album%)
$if(%PodcastCategory%,set "string=$meta_sep(PodcastCategory,|)"

setlocal enableDelayedExpansion
SET string=!string:^|=%%NL%%!
echo !string!>>"%%USERPROFILE%%\Desktop\taglisting.txt"
endlocal,)

$loopend()
@echo off
setlocal disableDelayedExpansion
set "file=%%USERPROFILE%%\Desktop\taglisting.txt"
set "sorted=%%file%%.sorted"
set "counted=%%file%%.counted"
set /a N = 1
REM Define a variable containing a linefeed character
set LF=^

REM The 2 blank lines above are critical, do not remove
sort "%%file%%" >"%%sorted%%"

"%%counted%%" (
set "prev=start"
for /f usebackq^ eol^=^%%LF%%%%LF%%^ delims^= %%%%A in ("%%sorted%%") do (

set "curr=%%%%A"
setlocal enableDelayedExpansion
if /i "!curr!" neq "!prev!" (
if "!prev!" neq "start" echo !n!	!prev!

endlocal
  set "prev=%%%%A"
  set /a N = 1

) else (
endlocal
set /a N += 1
)

)

setlocal enableDelayedExpansion
echo !n!	!curr!
endlocal

)

nul move /y "%%counted%%" "%%file%%"
del "%%sorted%%"
"%%USERPROFILE%%\Desktop\taglisting.txt"

___PodcastCategoryCounts.mte (1.37 KB)

Discovered a small bug in the script. It didn't handle percentage signs.

The key line should replaced to as follows:
$if(%PodcastCategory%,set "string=$replace($meta_sep(PodcastCategory,|),'%','%%')"

k