#!/home/bfiedler/anaconda3/bin/python import glob,os #maxdir=4 #maxdirn=8 #maxdirp=40 maxdir=2 maxdirn=40 # but all but f000 removed after 1 maxdirp=40 grbdirs = glob.glob("/home/bfiedler/play/grib/gfs1deg/*") print("gfs1deg:") grbdirs.sort() grbdirs.reverse() for grbdir in grbdirs: if not os.listdir(grbdir): print("empty:",grbdir) os.rmdir(grbdir) for grbdir in grbdirs[maxdir:]: command = 'rm -rf '+grbdir print(command) os.system(command) grbnpydirs = glob.glob("/home/bfiedler/play/grib/gfs1degnpy/*") grbnpydirs.sort() grbnpydirs.reverse() for grbnpydir in grbnpydirs[1:]: tdirs = glob.glob(grbnpydir+"/f*") tdirs.sort() for tdir in tdirs[1:]: # remove all but f000 command = 'rm -rf '+tdir print(command) os.system(command) print("gfs1degnpy:") for grbnpydir in grbnpydirs[maxdirn:]: command = 'rm -rf '+grbnpydir print(command) os.system(command) pngdirs = glob.glob("/home/bfiedler/play/grib/pngs/*") pngdirs.sort() pngdirs.reverse() print("pngs:") for pngdir in pngdirs[maxdirp:]: command = 'rm -rf '+pngdir print(command) os.system(command)