I still working on my big project, big at least for me, but I am currently stuck on this:
I have a lots of .shp, that I want to move to a gdb. While creating a feature class, I want to add date (YMD) before the name: test.shp -> _120706_test
Possibly the creation date of the SHP but also the importing date will be ok.
I created a list of feature and tried: _fc = '' + fc BUT AIN'T WORKING!
THANKS A LOT
# Import system modules
import sys, arcpy, datetime, os, traceback, time
from arcpy import env
# Load required toolboxes...
arcpy.AddToolbox("C:\\Program Files (x86)\\ArcGIS\\Desktop10.0\\ArcToolbox\\Toolboxes\\Data Management Tools.tbx")
# Get the active map document
import arcpy.mapping
mxd = arcpy.mapping.MapDocument ("CURRENT")
# List broken links
# arcpy.mapping.ListBrokenDataSources(mxd)
# Set environment settings
ws = "C:\\PARK"
arcpy.env.workspace = ws
print("env.workspace completed successfully")
installdir = arcpy.GetInstallInfo("desktop")
#check GDB exist
gdb_nam = "test.gdb"
gdb_full_path = os.path.join(ws,gdb_nam)
if os.path.exists(gdb_full_path):
arcpy.Delete_management(gdb_full_path)
print("GDB checked")
# Execute CreateFileGDB
arcpy.CreateFileGDB_management(ws, gdb_nam)
print("CreateFileGDB completed successfully")
outWorkspace = gdb_full_path
# Create a list of SHP in mxd
list = []
for df in arcpy.mapping.ListDataFrames (mxd):
for fc in arcpy.mapping.ListLayers (mxd, "", df):
if (fc.supports("DATASOURCE")) and (fc.dataSource.endswith(".shp")):
list.append(fc)
# Check for borken datasource
for fc in list:
if arcpy.mapping.ListBrokenDataSources(fc):
list.remove(fc)
# Check for projection
# Move fc to gdb
for fc in list:
rename (fc,'_'+fc.name)
arcpy.FeatureClassToGeodatabase_conversion(fc, gdb_full_path)
