Batch SMD to FBX script adjustments

Pretty much I have like 100+ SMD animations I need to convert into the FBX. After googling it I've found multiple scripts for doing so, to make it simple I'il give you an excample of the shortest one which works

import bpy
import os

for root, dirs, files in os.walk('/path/to/smd/files'):
for name in files:
if name.endswith('smd'):
# delete everything
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()
# adjust this to match the import smd operator
bpy.ops.import_scene.smd(filepath=os.path.join(root, name))
# export as fbx
bpy.ops.export_scene.fbx(filepath=os.path.join(root, name+'.fbx'))


But the problem is, while this script is importing\exporting all the files as it suppose, it completly breaks animations.

They are broken, because scene is not reseting for some reason, and batch ending up only exporting first smd correctly, while all the others would be overlaying each other ending up being broken.

In other words, first animation is alright, second one is exporting 1+2 animtion, third one is 1+2+3 and so on.