# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# Shapfile AddEditInfo & rename
# ListDatasets.py
# AddField.py
# Calculated.py
# Rename.py
# Created on: 2021-04-08 16:38:45.00000
#   (generated by ArcGIS/ModelBuilder)
# Description: 
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy
from arcpy import env
import os

# Set path but split country to Calculated and Rename.
path = "D:\\ArcMap test\\State\\"

country = "Bcountry"

arcpy.env.workspace = path + country + "\\"

# Until "Workfile" is "Get all Shp. file under this path."
# After "in_features" is "Set AddField."
datasets = arcpy.ListDatasets(feature_type='feature')
datasets = [''] + datasets if datasets is not None else []

for ds in datasets:
    for fc in arcpy.ListFeatureClasses(feature_dataset=ds):
        Workfile = os.path.join(arcpy.env.workspace, ds, fc)
        in_features = Workfile
        if arcpy.Exists(in_features):
            arcpy.AddField_management(in_features, "country", "TEXT", "", "",  50, "", "NULLABLE")
            arcpy.CalculateField_management(in_features, "country", 'country', "PYTHON", "")
            print fc + " fields are added."
        
#rename Shp.
in_data_railway = "railway.shp"
out_data_railway = country + "_railway.shp"

in_data_road = "road.shp"
out_data_road = country + "_road.shp"

data_type = "FeatureClass"

arcpy.Rename_management(in_data_railway, out_data_railway, data_type)
arcpy.Rename_management(in_data_road, out_data_road, data_type)

print "railway and road are renamed."
print "Finished."
