AnsweredAssumed Answered

True/False Statement for a definition

Question asked by matthewrusso on Apr 9, 2015
Latest reply on Apr 9, 2015 by dkwiens

Hi All,

 

I am trying to create a True Statement to check if a definition passed the "if"

 

On line 19 i am running "DEF RENAME" (Changes the name so the tool will run and I can fix it later)

Line 20 I want to know if Rename passed the if statement

 

My code is to change folders and shapefiles into a GDB while maintaining the structure of the folders.  Please let me know if you have advice or see a large issue.  The way I run this is through the command line.

 

def rename(variable):
    desc = arcpy.Describe(variable)
    name = desc.name
    new_name = "renamed"
    print name
    if " " or "-" or "0" or "1" or "2" or "3" or "4" or "5" or "6" or "7" or "8" or "9" in name:
        print("{0} is being changed to: {1}".format(name, new_name))
        arcpy.Rename_management(variable, new_name)
    else:
        pass

def import_to_GDB(input_workspace, output_workspace):
    import os
    base = os.path.basename(input_workspace)
    arcpy.CreateFileGDB_management(output_workspace, base)
    for dirpath, dirnames, filenames in arcpy.da.Walk(input_workspace):
        for dirname in dirnames:
            try:
                test = rename(dirname)
                if test == True:
                    dirname = "renamed"
                    dir_path = os.path.join(dirpath, dirname)
                    arcpy.env.workspace = dir_path
                    fcs = arcpy.ListFeatureClasses()
                    fds = os.path.join(output_workspace, base + ".gdb\\")
                    arcpy.CreateFeatureDataset_management(fds, dirname)
                    suboutput = os.path.join(fds, dirname)
                    count = 0
                else:
                    dir_path = os.path.join(dirpath, dirname)
                    arcpy.env.workspace = dir_path
                    fcs = arcpy.ListFeatureClasses()
                    fds = os.path.join(output_workspace, base + ".gdb\\")
                    arcpy.CreateFeatureDataset_management(fds, dirname)
                    suboutput = os.path.join(fds, dirname)
                    count = 0
            except:
                print("{0} had an error, passing to the next object".format(dirname))
            for fc in fcs:
                count = count + 1
                try:
                    arcpy.FeatureClassToGeodatabase_conversion(fc, suboutput)
                    print("{0} Complete".format(count))
                except:
                    print("{0} had an error, passing to the next object".format(fc))

Outcomes