bartdebruyn

listing gis files on disc

Discussion created by bartdebruyn on Mar 12, 2014
Latest reply on Jun 4, 2015 by blake.terhune
I have found this script to list shapefiles/geodatabases/dbase files/coverages on a disc.
The script runs well, BUT when i run it a second time, datalines are addded,; so my listing is getting larger every time.
I suppose it is because I use that yield command? Is there a way to avoid this? I am a new user of python/arc python. Can anyoen help me a little bit. I have already read that yield is difficult to understand for new users.
Thanks in advance,
Bart De Bruyn
****************************************************************

import os
import arcpy

workspace = r"T:\test"
output = r"H:\testlist.txt"
outFile = open(output, "w") 
lijn=""
  
def inventory_data(workspace, datatypes):
     """
     Generates full path names under a catalog tree for all requested
     datatype(s).
     Parameters:
     workspace: string
         The top-level workspace that will be used.
     datatypes: string | list | tuple
         Keyword(s) representing the desired datatypes. A single
         datatype can be expressed as a string, otherwise use
         a list or tuple. See arcpy.da.Walk documentation
          for a full list.
     """
     for path, path_names, data_names in arcpy.da.Walk(
             workspace, datatype=datatypes):
         for data_name in data_names:
             yield os.path.join(path, data_name)

for feature_class in inventory_data(r"T:\test", "Any"):

    lijn = lijn + feature_class + "\n"
    outFile.write(lijn)

outFile.close()

Outcomes