File system · 12 / 15 Exercise Hard

Organize by extension

Objective

The program runs inside a folder that already contains the files of the test case. mkdir(exist_ok=True) creates a folder and path.rename(target) moves (or renames) a file to another path.

Instructions

  • Move each file of the current folder (without touching subfolders) to a folder named as its extension, without the dot and in lowercase (for example foto.JPG goes to jpg/foto.JPG).
  • Files without extension stay where they are.
  • Show Files moved: n with the number of files moved.

Example. With notes.txt, photo.JPG, data.csv, README and b.txt you end up with txt/notes.txt, txt/b.txt, jpg/photo.JPG, csv/data.csv and README, and it shows Files moved: 4.

Output
Files moved: 4

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

Start exercise