1

I have the following python script that is used to move zip files from one folder to another and it works fine when executed before being published:

import shutil
import os

dir = r'C:\\arcgisserver\directories\arcgissystem\..path'

destination = r'C:\\arcgisserver\directories\arcgisjobs\..path'

for files in os.listdir(dir):
    if files.endswith('.zip'):
        shutil.move(files,destination)

However once I published this as a geoprocessing service and ran the resultant tool, the process succeeded however the files were not moved. Is it possible that something is being changed when the script is published as a service?

EDIT:

I accessed the published service script and it had changed to the following:

# Esri start of added variables
g_ESRI_variable_1 = 
os.path.join(arcpy.env.packageWorkspace,u'layer_updated_drawings')
g_ESRI_variable_2 = 
os.path.join(arcpy.env.packageWorkspace,u'dwgtozippedshapefile_gpserver')
# Esri end of added variables

import shutil
import os

dir = g_ESRI_variable_1
destination = g_ESRI_variable_2

for files in os.listdir(dir):
    if files.endswith('.zip'):
        shutil.move(files,destination)

However when I changed the values back to the paths as in the original code above I was getting an error on the last line :

shutil.move(files,destination)

The error was that although it was finding the file in the folder as it was mentioning the file by name in the error, for some reason it was not finding the same file in the same location to be moved. The resultant error is as follows:

Error executing tool. FileMove Job ID: j6133d03357794c498a5c06ff475024f8 : Traceback (most recent call last): File "C:\arcgisserver\directories\arcgissystem\arcgisinput\Toolbox\FileMove.GPServer\extracted\v101\my_toolboxes\FileMove.py", line 19, in shutil.move(files,destination) File "C:\Python27\ArcGISx6410.3\Lib\shutil.py", line 302, in move copy2(src, real_dst) File "C:\Python27\ArcGISx6410.3\Lib\shutil.py", line 130, in copy2 copyfile(src, dst) File "C:\Python27\ArcGISx6410.3\Lib\shutil.py", line 82, in copyfile with open(src, 'rb') as fsrc: IOError: [Errno 2] No such file or directory: 'Shapefile.zip' Failed to execute (FileMove). Failed to execute (FileMove).

1

The publisher tends to change paths in scripts.

You will find the published Python script if you dig into:

C:\arcgisserver\directories\arcgissystem\arcgisinput\[folder name?]\[Toolname].GPserver\extracted\v101\[some name]\

Check for modifications, if necessary fix the path, save, and restart the service.

  • I found where you said and changed the paths however I still got an error and the service didn't work at all. I have added an edit to the question that shows this. – Maeglin77 Jun 16 '17 at 12:45
  • The error message you added is a "File not found", I'll guess that shutil needs full path to the file. Try: shutil.move(os.path.join(dir, files), destination) – haakon_d Jun 22 '17 at 11:33
  • I did that and no errors were thrown, in fact the result is marked as successful however the file is still not moved. Any other possible explanations? – Maeglin77 Jul 4 '17 at 7:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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