File Operations Playground¶
Specification¶
The full specification below is extracted from Chapter 12: File Management, Packages, and Remote Access on the Pi 500+.
Type: microsim
**sim-id:** file-operations-playground<br/>
**Library:** p5.js<br/>
**Status:** Specified
Learning objective: Students will *apply* (Bloom L3: Apply) mkdir, cp, mv, and rm commands to predict how a virtual file tree changes after each command.
Canvas: 700x460px, responsive — recompute the file-tree panel and command-log panel widths as fractions of `width` inside `windowResized()`, stacking them vertically below 520px wide.
Layout: left panel shows a small virtual file tree (starting with `/home/pi/` containing `photos/` and one file, `robot_control.py`), rendered as indented labeled boxes. Right panel is a scrolling command log showing commands run so far and their effect in plain language.
Controls: four `createButton()` controls labeled "mkdir," "cp," "mv," "rm," each opening a small inline form (via `createInput()`) asking for the relevant file/folder name(s) before applying the operation; a `createButton()` labeled "Reset Tree" restoring the starting file tree.
Interaction: clicking a command button and filling in the requested name(s) updates the virtual file tree panel immediately — `mkdir` adds a new folder box, `cp` adds a duplicate file box, `mv` moves or relabels a box, `rm` removes a box entirely (with a brief red flash before it disappears, reinforcing that the action is permanent) — and appends a one-line plain-language description to the command log (e.g., "cp copied notes.txt to notes-backup.txt — the original still exists"). Clicking any existing box in the file tree shows its current full path in a small tooltip.
Implementation: p5.js. Represent the file tree as a nested JavaScript object rebuilt and redrawn each time a command is applied. Form input parsed on a button-triggered callback rather than every keystroke. Store the command log as an array of strings, capped at the most recent 8 entries, rendered with `text()` inside the log panel.