#!/usr/bin/env python3 """ Script to fix the path to the common files in Mageia html documentation Usage: python3 fix_common_path.py """ from os import walk from os.path import splitext, join import fileinput path_to_fix = 'mcc/4/tr' # first step: let's walk along the folder for root, dirs, files in walk(path_to_fix): # second step: identification of html files for elem in files: if splitext(elem)[1] == '.html': # third step: replacing the path with fileinput.input(files=join(root, elem), inplace=True) as f: for line in f: line = line.rstrip('\n') line = line.replace('"../common/', '"../../common/') line = line.replace('(../common/', '(../../common/') # with fileinput, you need to us 'print' and not 'write' to # write in the file print(line)