Can I select an Layer and Delete the others using macros?

I know I can select the others layers one by one using macros, but the layers that I want to delete sometimes comes with diferent names, so the macro will not work always.

Not quite clear on your question here - you want to select one layer and then delete all the other layers in a given file? If so, that probably would need a script for that to to work well, given that layers can have objects on them and both the layers and the objects be hidden or locked.

Yes, that’s it.
Select one layer and delete all the others