Select to view content in your preferred language

arcpy.ExportMetadata_conversion

929
3
07-10-2013 02:00 AM
JamesMitchell
Deactivated User
Hello,

Please can somebody provide some advice?

I have a text file containing the files i would like to export the metadata from e.g. 'D:\Temp\Cost\10_Kilometers_Buffer.shp'

I am trying to loop through this text file and export the metadata for each line. The only issue is on the line arcpy.ExportMetadata_conversion where i get the error

"Failed to execute. Parameters are not valid. ERROR 000732: Source Metadata: Dataset D:\Temp\Cost\10_Kilometers_Buffer.shp
  does not exist or is not supported The value does not exist. ERROR 000732: Source Metadata: Dataset D:\Temp\Cost\10_Kilometers_Buffer.shp does not exist or is not supported Failed to execute (ExportMetadata)."

If i change 'line' to r"D:\Temp\Cost\10_Kilometers_Buffer.shp" it works.

Any help will be greatly appreciated.

James

import arcpy, glob, os, string
import codecs


ListofLayers = codecs.open("C:\\Users\\34459jm\\Desktop\\DirPrnInfo.txt",encoding = 'utf-16')
 
# loop through the translator file
for line in ListofLayers:
 dir = arcpy.GetInstallInfo("desktop\\DirPrnInfo.txt")["InstallDir"]
 translator = dir + "Metadata/Translator/ESRI_ISO2ISO19139.xml"
 arcpy.ExportMetadata_conversion(line, translator, "c:\\Metadata\\" + os.path.basename(line) + ".xml")
Tags (2)
3 Replies
JamesMitchell
Deactivated User
Hi,

I have fixed the issue by using:

arcpy.ExportMetadata_conversion(line.replace('\r\n',""), translator, "c:\\Metadata\\" + os.path.basename(line.replace('\r\n',"")) + ".xml")
0 Kudos
StacyRendall1
Frequent Contributor
Suggest you read this http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//005700000009000000.htm

'\' is an escape character in Python strings, meaning that the path you passed to your tool is trying to do all kinds of crazy stuff. You have three options:

  • replace '\' with '\\'

  • replace '\' with '/'

  • specify that the entire string is a regular expression by putting an r at the start, like so: r'C:\Temp\Projects\shape.shp' (this ignores the escape character)

0 Kudos
RhettZufelt
MVP Notable Contributor
Hello,

import arcpy, glob, os, string
import codecs


#ListofLayers = codecs.open("C:\\Users\\34459jm\\Desktop\\DirPrnInfo.txt",encoding = 'utf-16')

ListofLayers = arcpy.ListFeatureClasses()

# loop through the translator file
for line in ListofLayers:
 dir = arcpy.GetInstallInfo("desktop\\DirPrnInfo.txt")["InstallDir"]
 translator = dir + "Metadata/Translator/ESRI_ISO2ISO19139.xml"
 arcpy.ExportMetadata_conversion(line, translator, "c:\\Metadata\\" + os.path.basename(line) + ".xml")



If you were to use an arcpy tool to get your list of featureclasses, then using the variable "line" would work.
Not sure what you have going on with the DirPrnInfo.txt file that you are extracting from, but if it is for the path/filename information, might want to take a look at arcpy.da.walk.  Will give you all in one swoop in a list that can be directly iterated through with your export conversion.

R_
0 Kudos