Change the contents of files according to rules