def dirwalk(dir):
    '''walk a directory tree, using a generator, rename certain directories
    replace particular strings in xml files on the way'''
    newname = 'newdir'
    for f in os.listdir(dir):
    	
        fullpath = os.path.join(dir, f)
        
        if os.path.isdir(fullpath) and not os.path.islink(fullpath):
        	
        	if checkdirname(f):
        		newname = f[:len(f)-2]+'-r'
        		renamedir(fullpath, os.path.join(dir, newname))
        		fullpath = os.path.join(dir, newname)
        	
        	for x in dirwalk(fullpath):
        			#print 'recursing in subdirectory: ', f , x
        			yield x
        if os.path.isfile(fullpath):
			print 'Saw file', fullpath
			
			if checkfilename(f):
				replacestrs(fullpath)
				
			yield f, fullpath	
        else:
        	
        	yield f, fullpath
walk a directory tree, using a generator, rename certain directories
    replace particular strings in xml files on the way
recipes/Python/435904_sedawk__Pythscript_rename_subdirectories/recipe-435904.py