I have a tool that I am publishing to ArcGIS Server and the tool runs fine except for one line

result = arcpy.Delete_management(newfolder)
if result.getOutput(0)=="true":
    message = "success"

What I don't understand is why the output of the result variable returns true when the Delete_management does not delete the folder I am passing it. I have tried shutil.rmtree as well with no success.

  • That code fragment is too small to be useful. What is the content of the newfolder variable?
    – Vince
    Nov 24, 2020 at 12:17
  • there is a filegdb and also a text file, all of these files are deleted when the tool is ran on the desktop before publishing to arcgis server, I was thinking that maybe the GP Service does not have permission to access the os to perform the operation. Nov 25, 2020 at 13:41

1 Answer 1


It's very difficult to provide an exact answer without knowing a lot more details, but I'll comment on both the Delete tool and using it inside a GP Service.

  1. The Delete tool returns true when it does what you've asked of it. So if you pass it a folder that doesn't exist, it gives True as a result. If it deletes the folder, it says True. You only get False if after the tool runs, the item is still there.


<Result 'true'>
  1. There is generally zero need to use Delete in a geoprocessing service. Delete is a mechanism to "clean up". Each and every GP Service execution runs in a it's own space. At the end of execution, after a set amount of time, the GP Framework cleans up everything that happens in that space. All your temporary files AND your output are simply cleaned up (deleted). Because of this, I don't recommend putting the Delete tool into your workflow. This adds execution time that the user needs to wait on. And for what? To have files removed on the server? Don't put this cost/time on the user.

  2. (This is what I think you're doing based on your comment). It sounds like you're passing a "folder" or "path" argument to the GP Service and hoping it'll delete said folder. First, the GP Service is executing on a remote server; not your desktop. As such, it can only delete items (files, folders, etc) that are either on that server, or the service has access too from that server itself. So if you've passed it c:\temp and that directory does not exist on the server, it can't reach back to YOUR CLIENT machine and delete it. You're accessing the service over web calls. It simply can't do this level of operations to your local machine. Beyond the GP Service on the Server accessing only items LOCAL to the service, it needs proper permissions to delete (or modify) files on that disk. Generally, ArcGIS Server is installed using a local user account (although it can be installed using a domain account). That user account generally does not have broad access to the Server box (think security concerns). The account has access to the Server install directory and the well defined $\arcgisserver\* directories where execution takes place. You'd need to give the account running Server explicit folder access to where you're trying to access.

Take the last point, and assume you've given the ArcGIS Server user account all access to the Server machine and you publish a GP Service with the delete tool (or os.remove or shutil.rmtree). Then, as a user I send in the path c:\windows to your service. Oooops!

  • The process I have creates a geodatabase inside of a folder, this folder is created inside of the folder where the gp tool is located on the server. Are you saying these files will be deleted automatically? Is that something that needs to be tasked inside of arcserver? Nov 25, 2020 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.