Project 04 · of 11
File reporting tool
Carried out in pairs with Léandro Berge, this “Processing data” SAÉ consisted in developing a Python application with a graphical interface to detect, visualise and manage the 100 largest files in a directory. The tool is aimed at system administration: quickly locating and deleting large files and analysing a directory tree to save time.
The tool is built around a pipeline combining PowerShell and Python. A PowerShell script launches the program; a first Python script handles the directory selection; a second one analyses the files, sorts the list by decreasing size and outputs a JSON file (gros_fichiers.json); a third one displays an interactive chart (pie chart, legends, tabs, buttons) from the JSON and generates a PowerShell script to delete the selected files, which is then executed.
The code is organised into dedicated modules (main.py, script1.py, script2.py, script3.py, plus modules creating the buttons, the pie chart, the legends and the tabs). It notably uses PyQt (QColor) for the interface and random colour generation, and pathlib (rglob, resolve, stat().st_size) to walk the tree and measure file sizes.
Several technical difficulties were encountered and solved: the syntax of the lambda function used to sort by size, error handling (no directory selected, empty JSON, no file to delete), and a first incorrect sort based on split(), simplified using two variables. In the end, the program does what it is expected to do: analyse, sort in decreasing order and generate a deletion script.
Develop, in pairs, a Python application with a graphical interface able to detect, visualise and manage (delete) the 100 largest files in a directory — a useful tool for system administrators.
- Launching the tool through a PowerShell script.
- Selecting the directory to analyse (
script1.py). - Analysis: walking the tree with
pathlib(rglob), measuring sizes (stat().st_size), sorting by decreasing size and creating the JSON (script2.py). - Displaying an interactive chart (pie chart, legends, tabs, buttons) from the JSON (
script3.py). - Generating a PowerShell script to delete the selected files.
- Running the deletion script.
- Mastering the lambda syntax to sort the list by size (
sort(key=lambda x: x[1], reverse=True)). - Implementing error handling: no directory selected, empty or missing JSON file, no file chosen for deletion.
- Fixing an incorrect size sort initially based on
split(), later simplified using two variables.
- AC13.01 — Use a computer system and its tools.
- AC13.02 — Read, run, fix and modify a program.
- AC13.03 — Translate an algorithm into a given language and environment.
- AC13.05 — Choose suitable data management mechanisms and justify those choices.
- AC13.06 — Fit into an environment suited to development and collaborative work.
The syntax of lambda functions and error handling in Python (no directory selected, empty JSON, no file to delete) took several attempts before I mastered them.
Splitting the tool into specialised scripts (directory selection, analysis/JSON, chart display, deletion script generation) to keep it readable and maintainable.
Working in pairs with a clear split of tasks, and commented code so that both of us could follow it.
- Complete Python tool (downloadable below).
- Project presentation (9 slides).
- Generated JSON file and automatically produced PowerShell deletion script.
Documents & files