How to replace name or delete .shp file from directory using Python QGIS ?
import os import processing input = "//input.shp" output = "//output_100.shp" interval = 100 processing.runalg("qgis:densifygeometriesgivenaninterval", input, interval, output) paths = (os.path.join(root, filename) for root, _, filenames in os.walk("C:/" + os.getenv('USERNAME') + "/SHP_Path") for filename in filenames) for path in paths: newname = path.replace('_100', '') if newname != path: os.rename(path, newname) Result:
WindowsError: [Error 183] Can't create existing file. I think that I should delete input.shp before renaming output.shp to input.shp. But If I'll try to delete that files (.shp, .dbf, .shx) with code:
filename="C:/" + os.getenv('USERNAME') + "/SHP_Path" + "//input.shp" if os.path.exists(filename): os.remove(filename) I 've got result:
WindowsError: [Error 32] The process can not obtain access to the file because it is being used by another process :
أكثر...
import os import processing input = "//input.shp" output = "//output_100.shp" interval = 100 processing.runalg("qgis:densifygeometriesgivenaninterval", input, interval, output) paths = (os.path.join(root, filename) for root, _, filenames in os.walk("C:/" + os.getenv('USERNAME') + "/SHP_Path") for filename in filenames) for path in paths: newname = path.replace('_100', '') if newname != path: os.rename(path, newname) Result:
WindowsError: [Error 183] Can't create existing file. I think that I should delete input.shp before renaming output.shp to input.shp. But If I'll try to delete that files (.shp, .dbf, .shx) with code:
filename="C:/" + os.getenv('USERNAME') + "/SHP_Path" + "//input.shp" if os.path.exists(filename): os.remove(filename) I 've got result:
WindowsError: [Error 32] The process can not obtain access to the file because it is being used by another process :
أكثر...