# This file is good for recursively searching through directory structures # and deleting .aux, .rrd and .tif.xml files. # It would be simple to delete other files, edit files and / or # do something else with this script. import sys, string, os, shutil strPath = '//terrain01/terrain/data/source/ussocom/sofprep/usa/ky/fort_campbell' strPath = os.path.abspath(strPath) blnUsage = 'false' blnRemoveTifXml = 'false' try: lstArg = sys.argv[1:] print 'Processing arguments...' i = 1 for strArg in lstArg: if (strArg == '-path') or (strArg == '-p'): strPath = lstArg[i] strPath = os.path.abspath(strPath) if (strArg == '-usage') or (strArg == '-u') or (strArg == '-help') or (strArg == '-h'): blnUsage = 'true' if (strArg == '-tifxml'): blnRemoveTifXml = lstArg[i] i = i + 1 except: print 'No arguments were provided, using defaults...' if (blnUsage == 'true'): print 'Usage: python delete_rrd_aux_xml.py -p ' print 'Usage: python delete_rrd_aux_xml.py -help' print 'Usage: python delete_rrd_aux_xml.py -tifxml true' print 'Usage: python delete_rrd_aux_xml.py -tifxml false' sys.exit(0) print 'Top Level Path:' print strPath def callback(arg, directory, files): for file in files: #print os.path.join(directory, file), repr(arg) #print os.path.join(directory, file) strFile = os.path.join(directory, file) strBase, strExt = os.path.splitext(strFile) #print strExt #print strBase intLen = len(strFile) intStart = intLen - 8 strTifXml = strFile[intStart:] #print strTifXml blnRemove = 'false' if (strExt == '.rrd') or (strExt == '.aux'): blnRemove = 'true' if (blnRemoveTifXml == 'true') and (strTifXml == '.tif.xml'): blnRemove = 'true' if (blnRemove == 'true'): print 'Deleting ' + strFile + '...' try: os.remove(strFile) except: print 'Error: Could not delete ' + strFile + '...' os.path.walk(strPath, callback, "secret message")