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)
Suspect the p variable is not getting passed correctly as the da.walk works fine for FGDB or the folder. Especially since the way you have it, it will only evaluate to False if you end up with an empty filenames list, which means that either p is the wrong path, or there is NODATA in there at all. Basically, da.walk makes a list, then you iterate through it and say "This file exists, so I put it in my list, if this file doesn't exist, then: so, the only way this would not be true is if the list is empty, so deleting that line here would have the same effect (minus the error of course on empty list). Also, the continue statement you have is not needed. Basically, it is the last line in the for loop. So, you are telling it, that when it is finished will all the code for the first item in the list, continue to the next. this is the default behaviour. Don't think it would make a difference, but possibly telling it to skip one?perhaps you need to set p = to:p = str(arcpy.GetParameterAsText(0)) or something. Like i said, don't tool script tools, so not sure how a single parameter gets passed.can print pand type(p) to make sure it is a string and the value is that actual path/name to the folder you want to walk through. 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)
for arcpy.Exists: Tests for the existence of feature classes, tables, datasets, shapefiles, workspaces, layers, and files in the current workspace
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?The spatial analyst toolbox should be here:c:\program files\arcgis\desktop10.1\ArcToolbox\Toolboxes\Spatial Analyst Tools.tbxR_Shoot, just saw something else going on here. Try the change in red above. you are checking to see if a file exists, da.walk reports filenames and directories sepratly, so you need to pass the path and name to locate the file. Just like in your describe statement.