The method texturepath = material.texture.filename returns the path/name of the material's texture's image-file. Use something like imagename = nil; imagename = File.basename(material.texture.filename) if material.texture...
To change a material's texture you use a new path material.texture="C:/.../mytetxure.png".
To get a material's name use matname = material.name.
To rename a material use material.name="newname" OR material.name=imagename if imagename - note that the renaming method is unavailable in older versions of Sketchup...