Q:

Deleting Files in a Folder, but not the Folder

I am encountering with two problems on deleting Files inside a Folder called Selection

The script is suppose to Delete ONLY Files inside the Selection Folder, but it deletes the Selection folder as well. 
The Selection folder has been deleted at very beginning of the running of script, bu I put the process at the end. In fact I need to analyze files stored in Selection, and after storing the final data in Final folder delete all the files inside the Selection, but not the folder itself.

Here is the code I am using to the files inside selection
for the_file in os.listdir(claendir):
    file_path = os.path.join(claendir, the_file)
    try:
        if os.path.isfile(file_path):
            os.unlink(file_path)
    except Exception, e:
        print e

and here is the entire code
import arcpy, shutil
from arcpy import env

# Set environment settings
env.workspace = "C:\\GISData\\Data"
InFeaturePath = "C:\\GISData\\Data\\"
claendir='C:\\GISData\\Selection\\'
shutil.rmtree(claendir);
InFeatureName = "band-tailed_pigeon.shp"
coulmn = "PataMN_1"
OutFeatureName ="HornedLark.shp"
InFeature = InFeaturePath + InFeatureName
OutFeaturePath ="C:\\GISData\\Final\\"
OutFeature = OutFeaturePath + OutFeatureName
dropFields = ["id","WTRSHD_FID"]

select_1 = "selected_1.shp"
select_2 = "selected_2.shp"
select_3 = "selected_3.shp"
select_4 = "selected_4.shp"
select_5 = "selected_5.shp"
dissolve_1 = "dissolved_1.shp"
dissolve_2 = "dissolved_2.shp"
dissolve_3 = "dissolved_3.shp"
dissolve_4 = "dissolved_4.shp"
dissolve_5 = "dissolved_5.shp"

# Process: Select
# Select 1
arcpy.Select_analysis(InFeature, select_1,  coulmn+ " <= 0.200000")
# Select 2
arcpy.Select_analysis(InFeature, select_2,  coulmn+ ">= 0.200001 AND " +coulmn+ " <= 0.400000")
# Select 3
arcpy.Select_analysis(InFeature, select_3,  coulmn+ ">= 0.400001 AND " +coulmn+ " <= 0.600000")
# Select 4
arcpy.Select_analysis(InFeature, select_4,  coulmn+ ">= 0.600001 AND " +coulmn+ " <= 0.800000")
# Select 5
arcpy.Select_analysis(InFeature, select_5,  coulmn+ ">= 0.800001 AND " +coulmn+ " <= 1")

# Process: Dissolve
# Dissolve 1
arcpy.Dissolve_management(select_1, dissolve_1, "", "", "MULTI_PART", "DISSOLVE_LINES")
print "Disolve 1 Finished"
# Dissolve 2
arcpy.Dissolve_management(select_2, dissolve_2, "", "", "MULTI_PART", "DISSOLVE_LINES")
print "Disolve 2 Finished"
# Dissolve 3
arcpy.Dissolve_management(select_3, dissolve_3, "", "", "MULTI_PART", "DISSOLVE_LINES")
print "Disolve 3 Finished"
# Dissolve 4
arcpy.Dissolve_management(select_4, dissolve_4, "", "", "MULTI_PART", "DISSOLVE_LINES")
print "Disolve 4 Finished"
# Dissolve 5
arcpy.Dissolve_management(select_5, dissolve_5, "", "", "MULTI_PART", "DISSOLVE_LINES")
print "Disolve 5 Finished"

print "Add Field Started ...."
# Process: Add Field
# Add Field 1
arcpy.AddField_management(dissolve_1, "type", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
# Add Field 2
arcpy.AddField_management(dissolve_2, "type", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
# Add Field 3
arcpy.AddField_management(dissolve_3, "type", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
# Add Field 4
arcpy.AddField_management(dissolve_4, "type", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
# Add Field 5
arcpy.AddField_management(dissolve_5, "type", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")

print "Add Field End "
print "Calculate Field Started ...."
# Process: Calculate Field
# Calculate Field 1
arcpy.CalculateField_management(dissolve_1, "type", "1", "VB", "")
# Calculate Field 2
arcpy.CalculateField_management(dissolve_2, "type", "2", "VB", "")
# Calculate Field 3
arcpy.CalculateField_management(dissolve_3, "type", "3", "VB", "")
# Calculate Field 4
arcpy.CalculateField_management(dissolve_4, "type", "4", "VB", "")
# Calculate Field 5
arcpy.CalculateField_management(dissolve_5, "type", "5", "VB", "")
print "Calculate Field End"
print "Delete Field Started ...."
# Process: Delete Extra Field
# Delete Field 1
arcpy.DeleteField_management(dissolve_1, dropFields)
# Delete Field 2
arcpy.DeleteField_management(dissolve_2, dropFields)
# Delete Field 3
arcpy.DeleteField_management(dissolve_3, dropFields)
# Delete Field 4
arcpy.DeleteField_management(dissolve_4, dropFields)
# Delete Field 5
arcpy.DeleteField_management(dissolve_5, dropFields)
print "Delete Field End"

print "Merge Started ...."
# Process: Merge
inFeaturesToMerge = [dissolve_1, dissolve_2, dissolve_3, dissolve_4, dissolve_5]
arcpy.Merge_management(inFeaturesToMerge, OutFeature)

for the_file in os.listdir(claendir):
    file_path = os.path.join(claendir, the_file)
    try:
        if os.path.isfile(file_path):
            os.unlink(file_path)
    except Exception, e:
        print e

Once again I need to delete ONLY files inside the Selection folder (and not the folder) and do this after finishing all analysis.

A:

You have this on line 8 of your full code:
shutil.rmtree(claendir);

This deletes claendir and everything below it.

