ScottChang25

ArcGIS 10:Doing Python to check for numbers of files in a directory-indentation err

Discussion created by ScottChang25 on Aug 17, 2012
Latest reply on Aug 29, 2012 by temge-esristaff
Hi all
I am using the following tutorial materials to pick up the Python programming:

(i)                  Python Programming for ArcGIS by David Quinn & Daniel Sheehan (dated: January 27, 2011)

(ii)                Python �?? Check for number of shapefiles in a directory in http://gis.stackexchange.com/questions/30059

I tried the following ArcPy code in my ArcMap 10:
 >>> import arcpy
>>> import os
>>> import glob 
>>> # Check numbers of shapefiles in a directory
>>> path = "C:\\TEMP\\"
>>> first = glob.glob(os.path.join(path,"NavyAnnexPt06move*"))
>>> first 
['C:\\TEMP\\NavyAnnexPt06move.dbf', 'C:\\TEMP\\NavyAnnexPt06move.prj', 'C:\\TEMP\\NavyAnnexPt06move.sbn', 'C:\\TEMP\\NavyAnnexPt06move.sbx', 'C:\\TEMP\\NavyAnnexPt06move.shp', 'C:\\TEMP\\NavyAnnexPt06move.shx']
>>> # Also to check for the only filename in path
 
>>> def file_check(path):
...      """Returns true if in path there is only one basename"""
... import os
... mlist = []I am using the following tutorial materials to pick up the Python programming:
...       for file in os.listdir(path):
...           if os.path.basename(file).split(".")[0] not in mlist:
...              mlist.append(os.path.basename(file).split(".")[0])
...     if len(mlist)>1:
...              return True
...       else:
...              return False
... 

Parsing error <type 'exceptions.IndentationError'>: unexpected indent (line 5)
>>> 


and I got an indentation error. Please help, advise and respond.

Thanks,
Scott Chang

Outcomes