I tried using
rgdal::writeOGR in R to overwrite a SHP file that was open in QGIS.
Error in writeOGR(x, "C:/myFiles", "testFile", : Creation of output file failed
Not only did it fail to overwrite the file, but it also deleted all the following auxiliary files:
testFile.cpg testFile.prj testFile.shx testFile.sbx
Basically everything except the
shp files. This seems to be standard behavior, and happens every time that I have a file open in QGIS. This also happens whether or not the file is being edited in QGIS.
I'm aware that it's possible to regenerate some of these to save the file, but I'd prefer to avoid this problem altogether by catching a QGIS file lock.
Is there any way (in Python, R or any other) to detect that QGIS has locked a file BEFORE trying to overwrite it? My operating system is Windows 10.