import string, sys, shutil, glob, os, arcpy #print sys.argv print arcpy.CheckOutExtension("Spatial") from arcpy.sa import * arcpy.env.overwriteOutput = True #check to see if scratch directory exists: if os.path.isdir(sys.argv[1] + "/working")<> True: arcpy.CreateArcInfoWorkspace_management(sys.argv[1], "working") if os.path.isdir(sys.argv[1] + "/output")<> True: arcpy.CreateArcInfoWorkspace_management(sys.argv[1], "output") arcpy.AddMessage ("Output workspace created") arcpy.env.workspace = sys.argv[1]
Solved! Go to Solution.
what I really want to do is see if a folder exists in the same folder as the script and if
it doesn't then create the folder.
import sys import os import arcpy # create a scratch folder in the same folder as the script Here = os.path.dirname(sys.argv[0]) if not arcpy.exists(os.path.join(Here,"working"): arcpy.CreateArcInfoWorkspace_management(Here, "working")
I'd suspect, based on your code, that you only have one argument passing to your script. In that case you would want sys.argv[0]. In Python, as in most computer languages, counting starts at 0.
sys.argv[0] should be the name of the script. sys.argv[1] would be the first parameter. This is different than GetParameterAsText.
Joan,
Unless you're going to be working with Arc/INFO coverages, you probably don't want to use CreateArcInfoWorkspace. Use os.mkdir to create a directory for storing shapefiles, or CreateFileGDB for a file geodatabase.
I keep getting the following error IndexError: list index out of range. Not sure what I am doing wrong.Might sound silly, but the only thing I can think of is that you haven't entered a value for the parameter, sys.argv[1]. Have you (ie. when you run the script, do you indicate which folder you want?)?
import arcpy, sys arcpy.AddMessage(sys.argv[1]) print(sys.argv[1])
what I really want to do is see if a folder exists in the same folder as the script and if
it doesn't then create the folder.
import sys import os import arcpy # create a scratch folder in the same folder as the script Here = os.path.dirname(sys.argv[0]) if not arcpy.exists(os.path.join(Here,"working"): arcpy.CreateArcInfoWorkspace_management(Here, "working")