ValidateTableName

Summary

Returns a valid table name for a workspace based on a table name and a workspace path. All invalid characters in the input table name are replaced with an underscore. The table name restrictions depend on the type of database.

Syntax

ValidateTableName (name, {workspace})
ParameterExplanationData Type
name

The table name that will be validated.

String
workspace

The workspace that will be used to validate the table name.

If the workspace is not specified, the Current Workspace environment will be used. If the Current Workspace environment is not set, a folder workspace will be used.

String
Return Value
Data TypeExplanation
String

A valid table name for the workspace.

Code sample

ValidateTableName example

Valid table names for the workspace are returned before copying.

import os
import arcpy

# Get the input and output workspaces.
arcpy.env.workspace = arcpy.GetParameterAsText(0)
out_workspace = arcpy.GetParameterAsText(1)

# Get a list of input feature classes to be copied and copy to new output 
# location.
for fc in arcpy.ListFeatureClasses():
    out_fc = arcpy.ValidateTableName(fc, out_workspace)
    arcpy.management.CopyFeatures(fc, os.path.join(out_workspace, out_fc))

Related topics