import arcpy import os p = arcpy.GetParameterAsText(0) arcpy.env.workspace = p newtable = r"H:/TableList.gdb/GISLibrary" list = [] for dirpath, dirnames, filenames in arcpy.da.Walk(p): for filename in filenames: if arcpy.Exists(os.path.join(dirpath, filename)): arcpy.AddMessage("adding file to list") descr = arcpy.Describe(os.path.join(dirpath, filename)) list.append([descr.catalogPath, descr.name, descr.dataType]) else: arcpy.AddMessage('File ' + filename + 'does not exist') continue with arcpy.da.InsertCursor(newtable, ['Path', 'FileName', 'Type']) as insert: for f in list: insert.insertRow(f)
EDIT: this code only works when i chose a geodatabase as input p. if I used a folder (that contained geodatabases) as input all of my feature classes were tagged as "do not exist)
The code above actually did not work the next day....but this should be correct (although this code is now saying all tools don't exist, might be I need to use something different than arcpy.Exists(filename) or how I defined the environment/workspace or setting my parameter as a workspace but still working that out)
Tests for the existence of feature classes, tables, datasets, shapefiles, workspaces, layers, and files in the current workspace
OIC, that makes sense. Any reason you can't just delete that 'extra' copy of the toolbox from your project drive? or, if it has been modified, move it somewhere?Or, could try something like this: for dirpath, dirnames, filenames in arcpy.da.Walk(p): for filename in filenames: if filename != "con": arcpy.AddMessage('adding ' + os.path.join(dirpath, filename) + ' to list............') descr = arcpy.Describe(os.path.join(dirpath, filename)) Since it is looking for that file and is haveing issues with it or the path, this should just make it move on to the next one if the current filename is "con".R_
for dirpath, dirnames, filenames in arcpy.da.Walk(p): for filename in filenames: if filename != "con": arcpy.AddMessage('adding ' + os.path.join(dirpath, filename) + ' to list............') descr = arcpy.Describe(os.path.join(dirpath, filename))
Don't think it was intended to look for "Tools", of course, a toolbox is a .tbx "file" so it should find them. However, I'm a little confused here. I don't do script tools, but I know that you have to tell the script what tool to use, where the toolbox is, etc. and I see no reference what so ever in your script to any tools or toolboxes. where are you defining them, and where are you calling the con tool that is giving you the error?
if arcpy.Exists(os.path.join(dirpath, filename)):
import arcpy import os p = arcpy.GetParameterAsText(0) arcpy.env.workspace = p newtable = r"H:/TableList.gdb/GISLibrary" list = [] for dirpath, dirnames, filenames in arcpy.da.Walk(p): for filename in filenames: if arcpy.Exists(os.path.join(dirpath, filename)): arcpy.AddMessage('adding ' + os.path.join(dirpath, filename) + ' to list............') descr = arcpy.Describe(os.path.join(dirpath, filename)) list.append([descr.catalogPath, descr.name, descr.dataType]) else: arcpy.AddMessage('ERROR: ' + os.path.join(dirpath, filename) + ' does not exist') continue with arcpy.da.InsertCursor(newtable, ['Path', 'FileName', 'Type']) as insert: for f in list: insert.insertRow(f)
Your suggestion to use .Exist worked perfectly.........Still very curious why it errored that "con" does not exist, we may never know The final product: import arcpy import os workspace = r"U:" newtable = r"H:/TableList.gdb/GISLibrary" list = [] for dirpath, dirnames, filenames in arcpy.da.Walk(workspace): if not arcpy.Exists(filenames): continue for filename in filenames: descr = arcpy.Describe(os.path.join(dirpath, filename)) list.append([descr.catalogPath, descr.name, descr.dataType]) with arcpy.da.InsertCursor(newtable, ['Path', 'FileName', 'Type']) as insert: for f in list: insert.insertRow(f)
import arcpy import os workspace = r"U:" newtable = r"H:/TableList.gdb/GISLibrary" list = [] for dirpath, dirnames, filenames in arcpy.da.Walk(workspace): if not arcpy.Exists(filenames): continue for filename in filenames: descr = arcpy.Describe(os.path.join(dirpath, filename)) list.append([descr.catalogPath, descr.name, descr.dataType]) with arcpy.da.InsertCursor(newtable, ['Path', 'FileName', 'Type']) as insert: for f in list: insert.insertRow(f)
import arcpy import os p = arcpy.GetParameterAsText(0) arcpy.env.workspace = p newtable = r"H:/TableList.gdb/GISLibrary" list = [] for dirpath, dirnames, filenames in arcpy.da.Walk(p): for filename in filenames: if arcpy.Exists(filename): arcpy.AddMessage("adding file to list") descr = arcpy.Describe(os.path.join(dirpath, filename)) list.append([descr.catalogPath, descr.name, descr.dataType]) else: arcpy.AddMessage('File ' + filename + 'does not exist') continue with arcpy.da.InsertCursor(newtable, ['Path', 'FileName', 'Type']) as insert: for f in list: insert.insertRow(f)
if not arcpy.Exists(filename): continue
>>> import arcpy >>> import os >>> workspace = r"H:/LIBTest" >>> newtable = r"H:/TableList.gdb/GISLibrary" >>> list = [] >>> for dirpath, dirnames, filenames in arcpy.da.Walk(workspace): ... for filename in filenames: ... descr = arcpy.Describe(os.path.join(dirpath, filename)) ... list.append([descr.catalogPath, descr.name]) ... >>> with arcpy.da.InsertCursor(newtable, ['Path', 'FileName']) as insert: ... for f in list: ... insert.insertRow(f) ...
Sure, I have done it a couple ways:Assuming the networked computer is named "server1" and has a share named "U" and/or is mapped to drive U: import arcpy workspace = arcpy.env.workspace = r"U:" ## don't put the slash at the end..... workspace = arcpy.env.workspace = r"\\server1\U" either works.Keep in mind, though, setting it to the base level, by default, will drill down into all directories in there as well, so it can take a long time if there is much there. Better to set it to a working folder on the drive. Mine is still running as it is categorizing my entire drive.R_
import arcpy workspace = arcpy.env.workspace = r"U:" ## don't put the slash at the end..... workspace = arcpy.env.workspace = r"\\server1\U"
indatabase = "Database Connections\\Connection to RCES_P.sde\\SIS_ADM.IMAGES" # can use the database connection indatabase = "C:\\Users\\rkzufelt\\AppData\\Roaming\\ESRI\\Desktop10.1\\ArcCatalog\\Connection to RCES_P.sde\\ARCUPDATE.MAPS" #or the database connection file
When topdown is True, the dirnames list can be modified in-place, and Walk() will only recurse into the subworkspaces whose names remain in dirnames. This can be used to limit the search, impose a specific order of visiting, or even to inform Walk() about directories the caller creates or renames before it resumes Walk() again. Modifying dirnames when topdown is False is ineffective, because in bottom-up mode the workspaces in dirnames are generated before dirpath itself is generated.
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.