def backup_dir(dir, ext='.bak'):
 n = 1
 extension = ext
 while os.path.exists((dir + extension)):
  n += 1
  extension = (ext + str(n))
 return (dir + extension)

def backup_dir ( dir , ext = '.bak' ) : n = 1 extension = ext while os . path . exists ( ( dir + extension ) ) : n += 1 extension = ( ext + str ( n ) ) return ( dir + extension )
figure out the name of a directory to back up the given dir to .