File system · 15 / 15 Exercise Medium

Batch rename

Objective

The program runs inside a folder that already contains the files of the test case. path.with_name(new) changes the name of a file keeping its folder, and f"{i:03d}" formats an integer with leading zeros.

Instructions

  • Add to each file of the current folder (without touching subfolders) a 3-digit numeric prefix according to alphabetical order: the first 001_, the second 002_, and so on. For example beta.txt becomes 002_beta.txt.
  • Show Files renamed: n.

Example. With beta.txt, alpha.txt and gamma.txt you end up with 001_alpha.txt, 002_beta.txt and 003_gamma.txt.

Output
Files renamed: 3

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise