Layer objects to Groups or Containers

I am trying to think of a way to use existing layers and convert them to groups or containers. So for example if I have Layer001 with 6 boxes in it with a right code I would be able to convert Layer001 to group with the same layer name. Any ideas how this would be achievable ?