Changing File Name and Reopening Renamed File by Sublime Text

This sample is for changing file name and reopening the file with new name. The flow is as follows.

  1. A file (sample.py) is opened.
  2. Rename the file from sample.py to newsample.py.
  3. The opened file is replace to the file with new name.
os.rename(oldfilewithpath, newname)
view = self.view.window().find_open_file(oldfilewithpath)
if view:
    view.retarget(newname)

 Share!