# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# Shapfile AddEditInfo & rename
# "for" loop
# ListDatasets.py
# Append.py
# Created on: 2021-04-14 18:09:12.00000
#   (generated by ArcGIS/ModelBuilder)
# Description: 
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy
import os

# main path
path = "D:\\ArcMap test\\State\\"

file_L = os.listdir(path)

# file path
for country_in_lower in file_L:
    country_name = country_in_lower.title()
    arcpy.env.workspace = path + country_in_lower + "\\"

    # Get all Shp in file path.
    datasets1 = arcpy.ListDatasets(feature_type='feature')
    datasets2 = [''] + datasets1 if datasets1 is not None else []

    for ds in datasets2:
        for fc in arcpy.ListFeatureClasses(feature_dataset=ds):
            railway_work = os.path.join(arcpy.env.workspace, ds, fc)

            railway = "railway"
            road = "road"

            # Append railway to new Shp.
            if railway in railway_work:
                railway_target_path = "D:\\ArcMap test\\Statcountry\\"
                railway_emptyFC = "C_and_S_railway.shp"
                schemaType = "No_TEST"
                arcpy.Append_management(railway_work, railway_target_path + railway_emptyFC, schemaType, "", "")
                print  country_name + "_railway features are Append."

                # Append road to new Shp.
            else:
                road_target_path = "D:\\ArcMap test\\Statcountry\\"
                road_emptyFC = "C_and_S_road.shp"
                schemaType = "No_TEST"
                arcpy.Append_management(railway_work, road_target_path + road_emptyFC, schemaType, "", "")
                print country_name + "_road features are Append."

print "Finished."
