This code works:# Import system modules
import arcpy
from arcpy import env
import os
# Set environment settings
env.workspace = "C:\\Users\\a391665\\Documents\\AAAAPERSONALE\\rugareto"
print("env.workspace completed successfully")
#check GDB exist
if os.path.exists("c:\\park\\test4.gdb"):
arcpy.Delete_management("c:\\park\\test4.gdb")
# Execute CreateFileGDB
arcpy.CreateFileGDB_management("C:\\park", "test4")
print("CreateFileGDB completed successfully")
# Set local variables
outWorkspace = "c:\\park\\test4.gdb"
print("outWorkspace completed successfully")
# Iterate
def fcs_in_workspace(workspace):
arcpy.env.workspace = workspace
for fc in arcpy.ListFeatureClasses():
print os.path.join(workspace, fc)
arcpy.FeatureClassToGeodatabase_conversion(fc, outWorkspace)
print os.path.join(workspace, fc, "TO GDB")
for ws in arcpy.ListWorkspaces():
fcs_in_workspace(os.path.join(workspace, ws))
fcs_in_workspace("C:\\Users\\a391665\\Documents\\AAAAPERSONALE\\rugareto")
If I use this: arcpy.CopyFeatures_management(fc, outWorkspace)I don't get any error but the gdb is empty.If I add:
# Iterate
def fcs_in_workspace(workspace):
arcpy.env.workspace = workspace
for fc in arcpy.ListFeatureClasses():
print os.path.join(workspace, fc)
outFeatureClass = os.path.join(outWorkspace, fc.strip(".shp"))
arcpy.CopyFeatures_management(fc, outWorkspace)
print os.path.join(workspace, fc, "TO GDB")
for ws in arcpy.ListWorkspaces():
fcs_in_workspace(os.path.join(workspace, ws))
fcs_in_workspace("C:\\Users\\a391665\\Documents\\AAAAPERSONALE\\rugareto")
I get this:Traceback (most recent call last): File "C:\Python26\ArcGIS10.0\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 312, in RunScript exec codeObject in __main__.__dict__ File "C:\Users\a391665\Desktop\Script2_subfolders_test.py", line 13, in <module> arcpy.Delete_management("c:\\park\\test4.gdb") File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\management.py", line 3031, in Delete raise eExecuteError: ERROR 000601: Cannot delete c:\park\test4.gdb. May be locked by another application.Not that I care about CopyFeatures_managment but it seems to be fast, when I sue it out of this script obviously