from qgis.core import *
suffix = "_foo"
pathToFile = "/path/to/wherever/"
layers = iface.legendInterface().layers()
for layer in layers:
newName = layer.name() + suffix + ".shp"
ret = QgsVectorFileWriter.writeAsVectorFormat(layer, pathToFile + newName, "utf-8", None, "ESRI Shapefile")
if ret == QgsVectorFileWriter.NoError:
print newName + " saved to " + pathToFile + "!"
from qgis.core import *
suffix = "_foo"
pathToFile = "/path/to/wherever/"
layers = iface.legendInterface().layers()
for layer in layers:
newName = layer.name() + suffix + ".shp"
ret = QgsVectorFileWriter.writeAsVectorFormat(layer, pathToFile + newName, "utf-8", None, "ESRI Shapefile")
if ret == QgsVectorFileWriter.NoError:
print newName + " saved to " + pathToFile + "!"
For Raster Layer use the QgsRasterFileWriterQgsRasterFileWriter
€P.S.: You You can find a more detailed example in the CookbookPyQGIS Developer Cookbook.