How to batch rename materials or auto assign them to the name of the texture file I'm currently working on porting a section of a world/map from one game to use in source filmmaker. I've managed to import the section I wanted and I'm stuck at a very slow and repetitive process.

What I have is dozens of objects (which I imported directly from my game), the material names were assigned based on the name of the object and the texture was set accordingly.

So lets say an object I imported is called chair, and this object has 3 materials or so. Each material will be named chair.001, chair.002, chair.003, etc etc. Now, the texture files/images are named correctly, lets say the textures are named chairwood chairclooth chairmetal or something of that sort. What I need is to be able to automatically merge the names of the materials with the textures they are assigned, so whatever the filename is the material is automatically changed to it. Several of the objects I have use the same texture file whilst having differently named materials, so you can see why its a royal pain.

Pretty much I need to know if I can do any of the following things with or or without existing addons/scripts or default tools in blender.
1) Can you select/batch multiple materials and rename them to all have the same name?
2) Convert/export textures to have them the same as the material? 

I've included a imgur link of what I'm trying to explain, maybe it'll be easier to understand what I'm getting at
https://i.imgur.com/GXsb332.png
Using blender internal, the textures can be found in bpy.data.textures. By looping through this you can easily match the texture name to the image it has.

import bpy

for tex in bpy.data.textures:
    if tex.type == 'IMAGE':
        tex.name = tex.image.name


Usually the image name is its filename without extension, if you have image names with extensions, you can use os.path.splitext to remove the extension.

tex.name = os.path.splitext(tex.image.name)[0]