Prevent creation of XML files for geoprocessing results

3242
7
05-03-2013 01:38 AM
JosephBarraud
New Contributor II
I have a Python script that I use to create a text file containing the list of files in a folder for example.

The name of the output text file is one of the parameters of the tool and needs to be defined with Direction = Output (otherwise the tool complains that the file does not exist). The consequence is that a description file (an .xml file) is created by ArcGIS once the tool has finished running.

Is there a way to prevent ArcGIS from creating this .xml file?
7 Replies
DavidMartin
Occasional Contributor II
If that's happening, it sounds like you're using an ArcGIS tool or arcpy command to create the text file?? ArcGIS often keeps metadata on its datasets in xml files. I'd switch to using Python's built-in open() function:

with open("filename.txt", "w") as f:
    f.write("my_list_of_files_as_a_string")
0 Kudos
JosephBarraud
New Contributor II
David,
Thanks for your reply. But I am doing exactly what you've suggested. I have a "with open(...) as f:" command and the script is almost pure Python. I am using arcpy only for the GUI.
I have even tried to delete the XML file within the script but this file is actually created after the tool has finished running.
DavidMartin
Occasional Contributor II
I would look more closely at what you are doing with arcpy, in that case. I have just created the script below, and from it built a script tool with a single output parameter (a file). When I run it, I don't find an xml file is created, only my text file.

import arcpy

with open("e:\\filename.txt", "w") as f:
     f.write("my_list_of_files_as_a_string")
     arcpy.SetParameter(0, f)
0 Kudos
JosephBarraud
New Contributor II
I have got my answer then: using "SetParameter" does prevent the creation of the XML file.

This is a simplified version of my original code:
# Import system modules
import os

# Import ArcGIS module
import arcpy

# Get the parameters
folderName = arcpy.GetParameterAsText(0)
destTxtFile = arcpy.GetParameterAsText(1)

# Create list of files in the directory
listFiles = os.listdir(folderName)

# Open output txt file
with open(destTxtFile,'w') as txtfile:
    
    # Loop through the list of files
    for fileName in listFiles:
        baseName = os.path.basename(fileName)
        (nameRoot,ext) = os.path.splitext(baseName)
        
        if ext == ".asc":
            txtfile.write(baseName)
    
    #arcpy.SetParameter(1, txtfile)


This does create an XML file along with the text file. If I uncomment the last line, the XML file has gone.

Thank you.
0 Kudos
DavidMartin
Occasional Contributor II
Interesting. I wonder if this is version-specific? If I run your script (with or without the SetParameter line commented out), I don't get an xml file created - just a text file. I'm on 10.1 SP1.

Even if I change the type of the output parameter in the script tool to "Dataset" or "Table", I still don't get an xml file generated.

Glad you're sorted though!
0 Kudos
JosephBarraud
New Contributor II
There might be an option somewhere I have turned on or something like that... I am also running ArcGIS for Desktop Basic 10.1 SP1.
I have tried File, Text File and Dataset for the type of the output in the tool, with the same result.

To be complete, this tool was part of a standard toolbox, not a "Python toolbox".
0 Kudos
ChigoZeerem
New Contributor

Hey all, 

An easier fix that I discovered would be to turn off the logging history by using the line: 

arcpy.SetLogHistory(False) 

The documentation for its use can be found here: 

SetLogHistory—Help | ArcGIS Desktop 

Hope it works for you

Cheers