debragajdosFM0

Py 2.4 - os.walk and using sys.argv

Discussion created by debragajdosFM0 on Feb 7, 2012
Latest reply on Feb 7, 2012 by csny490
Hi everyone,

I have a script that walks through a multi-level directory. I would like to be able to use sys.argv to call the workspace, and run thru and do the process.  The script works when I hard code to the top level directory.  When I add the sys argv, It doesn't run.

import arcgisscripting, sys, os

gp = arcgisscripting.create()

try:
    def treeDir (arg, dirpath, basenames):
        gp.workspace = dirpath
        lines_list = []
        for f in basenames:
             if f == "lines.shp":
                fullf = os.path.join(dirpath,f)
                print "file=" + fullf 
                               
                #Process: Add Field ...
                try:
                    gp.AddField_management(fullf, "NewField", "DOUBLE", "10", "8", "", "", "NON_NULLABLE", "NON_REQUIRED", "")
                                 
                except:
                    print ("gp didn't work correctly")
                    
                    
                    #Add A Completion Message

                print ("Well done.")

    root = sys.argv [1]           ## or hard code the path to top level##
    os.path.walk(root,treeDir,None)
except:
    print ("Something went wrong.")


I would like to be able to set up arguments for field parameters as well, but first things first...

I have a second part to this question which involves Feature Class to Coverage, but I will start a second thread for that.  I will also be running that gp tool in the walk script.

Thanks in Advance.

Outcomes