# copyShapefiles.py
# Purpose:      For each folder in the subdirectory,
#               copy the polygon and point shapefiles to
#               respective output directories.
# Usage: input_directory output_directory
# Example input: C:/gispy/data/ C:/gispy/scratch
import arcpy, os, sys

baseDir = sys.argv[1]
arcpy.env.workspace = baseDir
outDir = sys.argv[2]
arcpy.env.overwriteOutput = True

polyDir = os.path.join(outDir, 'polyFiles/')
pointDir = os.path.join(outDir, 'pointFiles/')
for myDir in [polyDir, pointDir]:
    if not os.path.exists(myDir): #Book section 9.5
        os.mkdir(myDir)

files = os.listdir(baseDir) #Book section 10.3
for f in files:
    fullPath = os.path.join(baseDir, f)
    if os.path.isdir(fullPath):
        print('Shapefiles in {0}:'.format(fullPath))
        arcpy.env.workspace = fullPath
        curFiles = os.listdir(fullPath)
        for nestedF in curFiles:
            desc = arcpy.Describe(nestedF) #Book section 9.3
            if desc.DataType == 'ShapeFile':
                if desc.ShapeType == 'Polygon':
                     arcpy.Copy_management(nestedF, polyDir + nestedF)
                     print('{0} copied  to {1}'.format(nestedF, polyDir + nestedF))
                elif desc.ShapeType == 'Point':
                     arcpy.Copy_management(nestedF, pointDir + nestedF)
                     print('{0} copied  to {1}'.format(nestedF, pointDir + nestedF))