11 rename_file()

The function rename_file() renames files in a directory based on a given pattern. It has three inputs:

  1. filepath, which specifies the desired directory of where the files to be renamed are;
  2. pattern_now, which is a regular expression pattern of the file names as they currently are; and
  3. pattern_new, which is the desired string that replaces the file names detected in pattern_now.
# From a folder, replace file names having "Fall 2018" with "Spring 2019."
rename_file('C:/my/folder/', 'Fall 2018', 'Spring 2019')