In this assessment, you will create a basic terminal shell-style program allowing users to manage (virtual) files and folders.

Paetae/A: Creating a computer program involves:

  • writing code for a program that performs a specified task
  • setting out the program code clearly and documenting the program with comments
  • testing and debugging the program to ensure that it works on a sample of expected cases
  • A complex computer program:
    • uses variables storing at least two types of data (e.g. numeric, text, Boolean, object)
    • uses sequence, selection and iteration control structures (if/switch/match, for, while, etc.)
    • takes input from a user, sensors, or other external source
    • produces output
    • uses two or more complex programming techniques
      • programming or writing code for a graphical user interface (GUI)
      • reading from, or writing to, files or other persistent storage
      • object-oriented programming using objects defined by the student
      • using third party or non-core API, library or framework
      • using complex data structures (e.g. stacks, queues, trees)

Kaiaka/M: Creating a well-structured computer program involves:

  • documenting the program with appropriate names and comments that describe code function and behaviour
  • following common conventions for the chosen programming language
  • testing and debugging the program effectively to ensure that it works on a sample of both expected cases and relevant boundary cases

Kairangi/E: Creating a flexible and robust computer program involves:

  • ensuring that the program is a well-structured, logical response to the specified task
  • making the program flexible and robust
  • comprehensively testing and debugging the program

  • 🗓 You have five (5) spells in which to complete your task during class time
  • 🏫 You may work on this assessment outside of class
  • 💬 You may communicate with others in the class quietly
  • 🌎 You may consult the web during this assessment
  • 📖 You must NOT submit code that you did not 100% write as your own
    • This includes:
      • code copied from your neighbours
      • code you get help with from outside sources (whānau, friends, internet)
      • code generated by a large language model (Copilot, ChatGPT, etc.)
    • You may use AI to give suggestions for approaches but you must not copy any code samples
      • To help avoid temptation, specifically tell the AI "Do not give me code samples"
    • If you find code that goes beyond mere inspiration, please cite where you found the code in a double-slash comment. For example:
      // This code is based on a sample found on https://stackoverflow.com/questions/58051099/how-do-i-format-a-string-from-a-string-with-in-swift
      let greeting: String = String(format: "Hello! Your name is ‘%@’", name)
    • You may not cite code generated by AI as each generation is ephemeral (i.e. neither your kaiako nor an external moderator will be able to access the conversation).

Teleprinter

A terminal emulator is a computer program that simulates a text-based computer terminal.

In the early days of networked computing, computers were used by connecting to them with a teleprinter; you typed in text-based commands and their output would be printed on paper.

In the modern day, terminal emulators allow you to send commands to a computer without the need for a teleprinter.

Modern terminal emulators include Windows Terminal on Windows 11, Terminal and iTerm 2 on macOS, and so on. Visual Studio Code includes a built-in terminal emulator.

Terminals typically allow you to use a shell, a program that runs other programs. Shell programs let you type in text-based commands followed by arguments — this is similar to calling functions in a programming language.

A shell is the software that interprets the commands sent by a terminal emulator/teleprinter. In general, shells understand a series of built-in commands or defer to programs stored on the computer.

Examples of shells include PowerShell used on Windows, zsh used on macOS, and bash used on most Linux distributions.

In our program, all of the commands will be built-in. You will create the commands to run in the shell.

Make sure that you have completed the file system activity from Trees and Nodes. You should have:

  1. a FilesystemNode protocol, describing what a filesystem node contains (i.e. a name, an optional parent)
  2. an extension to FilesystemNode so that it conforms to CustomStringConvertible
  3. a Folder struct conforming to FilesystemNode, which additionally contains child nodes (folders) and can add items to itself (add(_:))
  4. a File struct conforming to FilesystemNode
  5. a selection of Folder and File objects

If you don't have this structure, you are free to create your own structure to complete the task (i.e. using arrays and/or dictionaries). You will need to add the savejson and/or loadjson command to compensate for the absence of a complex data structure or object-oriented programming.

  1. Create a prompt that shows the current folder. Any of the commands below affects the objects in the current folder
  2. Allow the users to type the following commands:
    • ls to show the names and sizes of folders and files in the current folder
      • folders are shown first, in alphabetical order
      • files are shown after that, in alphabetical order
      • at the end of the command output, show the total size of the contained files and folders
    • touch <filename> <filesize> to create a new file that is 1 KB by default, or an optionally specified size
      • File names may NOT contain spaces
      • File sizes are always given in KB
      • Files must be at least 1 KB
      • Files can be up to 4 GB (4194304 KB)
      • Adding file size support is only for Kairangi/E
      • Example usage:
      • touch myfile.txt (creates a 1 KB file)
      • touch backup.dat 4096 (creates a 4096 KB file)
    • mkdir <foldername> to create a new folder in the current folder
      • Folder names may NOT contain spaces
      • Adding explicit full path support is only for Kairangi/E
      • Example usages:
      • mkdir myfolder
      • mkdir /home/myname/myfolder (explicit full path)
    • rm <filename> to delete a file in the current folder. If no such file exists, tell the user
      • rm can only delete files, not folders
      • Adding explicit full path support is only for Kairangi/E
      • Example usages:
      • rm myfile.txt
      • rm /home/myname/myfile.txt (explicit full path)
    • rmdir <foldername> to delete a folder in the current folder. If no such folder exists, tell the user
      • rmdir also deletes all the files and subfolders contained within the specified folder
      • Folder names may NOT contain spaces
      • Adding explicit full path support is only for Kairangi/E
      • Example usages:
      • rmdir myfolder
      • rmdir /home/myname/myfolder (explicit full path)
    • cd <foldername> to change to a different folder
      • If the provided foldername is .. move to the parent folder
      • Folder names can contain spaces
      • Adding explicit full path support is only for Kairangi/E
      • Example usages:
      • cd myfolder
      • cd ..
      • cd /home/myname/myfolder (explicit full path)
  3. If you plan to use the reading/writing files complex technique instead of one of the other techniques (OOP, complex data structures), then you may add one of the following commands:
    • savejson to save the entire virtual hard drive's folder structure as a JSON file, OR
    • loadjson to load the virtual hard drive from a JSON file

There are also the following requirements to ensure the program is robust:

  • Your program starts with the following directories by default:

    • home — the root folder
      • documents - contains two (2) files (cv.pdf, data.dat)
      • downloads - contains no files
      • music - contains ten (10) files (1.mp3 through to 10.mp3)
      • photos - contains a folder and two (2) files (passport.jpg, photoid.png)
        • japan2026 - contains five (3) files (tokyo.png, kyoto.jpg, miyajima.gif)
  • File and folder names must contain at least one (1) character, up to a maximum of twelve (12)

  • File names must have a dot (.) followed by a three (3) character file extension

  • File and folder names must only contain lower-case alphanumeric characters (no punctuation or spaces other than the dot for the extension)

  • You may not:

    • Create actual files and folders — save reading/writing files for the savejson/loadjson command, if you choose to include it/them
    • Delete the shell's current folder, only ones contained within that folder
    • Leave files and folders orphaned when their containing folder is deleted — you must delete them as well

/home/myname> ls
documents/      (dir - 2 KB)
downloads/      (dir - 0 KB)
music/          (dir - 10 KB)
photos/         (dir - 7 KB)
TOTAL: 19 KB

/home/myname> cd photos

/home/myname/photos> ls
japan2026/      (dir - 3 KB)
passport.jpg    1 KB
photoid.png     1 KB
TOTAL: 5 KB

/home/myname/photos> rm passport.jpg

/home/myname/photos> touch japan2026/banana.jpg

/home/myname/photos> touch japan2026/apple.jpg

/home/myname/photos> ls
japan2026/      (dir - 5 KB)
photoid.png     1 KB
TOTAL: 6 KB

/home/myname/photos> cd ..

/home/myname> rmdir photos

/home/myname> ls
documents/      (dir - 2 KB)
downloads/      (dir - 0 KB)
music/          (dir - 10 KB)
TOTAL: 12 KB

/home/myname> rm documents
documents is a folder

/home/myname> rmdir banana
Bad command or filename

/home/myname> purplemonkeydishwasher
Bad command or filename