For a start, you're adding a new group each time the script is run. Your script doesn't count layers in groups. You have to have a recursive function to find all the layers (including groups and sub groups). Working with groups is a pain :(
I've modified your code to allow for a recursive function:
var Doc = activeDocument;
var newLayerSet = Doc.layerSets.add();
var count = 0;
var allLayers = new Array();
var theLayers = collectAllLayers(app.activeDocument, 0);
count = theLayers;
alert("A: " + allLayers.length); //A
alert("B: " + count); //B
// function collect all layers
function collectAllLayers (theParent, level)
{
for (var m = theParent.layers.length - 1; m >= 0; m--)
{
var theLayer = theParent.layers[m];
// apply the function to layersets;
if (theLayer.typename == "ArtLayer")
{
if(theLayer.name.indexOf ("MMRE") != -1)
{
theLayer.move(newLayerSet, ElementPlacement.INSIDE);
}
}
else
{
allLayers.push(level + theLayer.name);
collectAllLayers(theLayer, level + 1)
count++;
}
}
return count;
}
Doc.layers, it gets shorter while you iterate over it (I assume). - deceze