Feature class name wildcard

4659
10
12-21-2017 10:41 AM
CCWeedcontrol
Occasional Contributor III

I have a feature class table that i need to export to excel, the feature class will be created weekly. The problem i am having is that on creation the feature class gets the date added to the end of the feature class name and i am trying to access with a wildcard because the date will change based on when the feature class gets created. How can i get the feature class with a wildcard?

import arcpy  
 
workspace = "Database Servers\GIS.gds\GISSERVER1 (VERSION:dbo.DEFAULT)" 
arcpy.env.workspace = workspace

'''
lyrs = ['Hyrdo_FINAL_ALL_*']  
for fc in arcpy.ListFeatureClasses():  
    for lyr in lyrs:  
        if fc.startswith(lyr):
            print 'lyr'
'''
lyr = "Hyrdo_FINAL_ALL_*" #Database Servers\GIS.gds\GISSERVER1 (VERSION:dbo.DEFAULT)\Hyrdo_FINAL_ALL_121817
arcpy.MakeFeatureLayer_management(lyr, "In_memory\lyr1")

arcpy.TableSelect_analysis("In_memory\lyr1","C:/Temp/Export_Output.xls", "")


print 'done'
0 Kudos
10 Replies
CCWeedcontrol
Occasional Contributor III

I was able to get it to work by removing the feature_dataset [0] and making the workspace a "database connection" not a direct connection.

import arcpy
from arcpy import env

arcpy.env.workspace = "Database Connections\GISSERVER1 (VERSION:dbo.DEFAULT)"

lyr = arcpy.ListFeatureClasses ("Hydro_FINAL_ALL_*")#Database Servers\GIS.gds\GISSERVER1 (VERSION:dbo.DEFAULT)\Hyrdo_FINAL_ALL_121817
for fc in lyr:
    arcpy.MakeFeatureLayer_management(fc, "In_memory\lyr1")
    arcpy.TableSelect_analysis("In_memory\lyr1","C:/Temp/Export_Output.xls", "")
    #arcpy.FeatureClassToFeatureClass_conversion("In_memory\lyr1","C:\Temp","Export.shp")


print 'done'
0 Kudos