I have a shapefile which resides in a folder, gets processed and the output is saved in another folder. Before the output, I would like to rename the shapefile slightly differently from the original:
eg.
"France (A).shp" -> "France (B).shp"
The following is the script I am using but comes up with a "cannot find file" error:
root_dir = "C:\Users\xxxx\Desktop\Test\\"
original_dir = 'Original files'
processed_dir = 'Processed files'
outputs_1=general.runalg("qgis:creategrid", 1000, 1000, 24108, 18351.157175, 258293.802316, 665638.226408, 1, 'EPSG:7405', None)
for path, subdirs, files in os.walk(root_dir):
if original_dir in path:
for file in files:
if file.endswith('.shp'):
newFile = rename(file, file.replace("(O).shp", "(P).shp"))
outputs_2=general.runalg("qgis:clip", outputs_1['SAVENAME'], os.path.join(os.path.dirname(path), original_dir, file), os.path.join(os.path.dirname(path), processed_dir, newFile)
Is this the right way to go about changing the filename?
I also checked stackoverflow for some tips.
rename
andreplace
instead ofinsert
but kept getting errors.