Posts

Showing posts with the label Python

Rename Sub Folders in A Directory With Python

Here's a little bit of code that renames sub folders in a directory with python. import os import os.path for (dirpath, dirnames, filenames) in os.walk(r'O:\!2016\your folder path here):     for idx in range(len(dirnames)):         print(dirnames[idx])         newname = dirnames[idx].split(' ')[0].upper() + " " + dirnames[idx].split(' ')[1].upper()         os.rename(os.path.join(dirpath, dirnames[idx]), os.path.join(dirpath, newname))         dirnames[idx] = newname

Sequential Numbers

In ArcMap, here is how you can calculate sequential numbers using Field Calculator. Set field calculate to python. Paste this in pre logic script: rec=0 def autoIncrement():  global rec  pStart = 1   pInterval = 1  if (rec == 0):    rec = pStart   else:    rec += pInterval   return rec Paste this in second box autoIncrement() Check out one of my other posts about how to Convert from Degrees Minutes Seconds to Decimal Degrees in Python here . Happy GISing! Lindsy Hales Bentley

How to pull numbers out of a string

Here’s a little function to pull numbers out of a string. import re def calculate(value):   newVal = re.sub("[^0-9]", "", value)   if newVal == "":     return 0   elif newVal is None:     return 0   else:     return newVal calculate( !Size! ) Happy GISing! Lindsy Hales Bentley