I wrote the code below to save selected layers in the layerTree
to a folder by Python, some of them are temporary layers, I don't know if it matters, and my main purpose is to save those temporary layers altogether. The code executed without error, but nothing in the direct folder:
for lyrs in iface.layerTreeView().selectedLayers():
path = "C:/Users/xxx/Documents/A_work/Scripts"
os.chdir(path)
basename=lyrs.name()
SHPname = basename +'.shp'
SHPpath= path + '/' + SHPname
QgsVectorFileWriter.writeAsVectorFormat(lyrs,SHPpath,'utf-8',lyrs.crs(),'SHP', layerOptions=['ESRI Shapefile'])