Welcome, guest | Sign In | My Account | Store | Cart

Written as a tribute to recipe 440636, this newest version is considerably reworked.

Python, 17 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import sys
import os

def main():
    # Process old and new path names.
    old_path = sys.argv[0]
    root, file = os.path.split(old_path)
    name, extension = os.path.splitext(file)
    new_path = os.path.join(root, str(int(name) + 1) + extension)
    # Start a new program generation.
    with open(old_path, 'rb') as old_file, open(new_path, 'wb') as new_file:
        new_file.write(old_file.read())
    os.remove(old_path)
    os.startfile(new_path)

if __name__ == '__main__':
    main()

This program is a personal benchmark for reflecting about five more years in Python.