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).