Skip to content

File Path Resolver

Run the File Path Resolver MicroSim Fullscreen

You can include this MicroSim on your website using the following iframe:

<iframe src="https://dmccreary.github.io/robot-arm/sims/file-path-resolver/main.html"
        height="626px" width="100%" scrolling="no"></iframe>

Description

Work out which file a path reaches from a given working directory in eight problems on a small project folder tree, see each step of the resolution, then try your own paths. Used in Chapter 1.

The tree shows the folder /home/maker with the arm-lab project inside it. Folders are drawn in bold with a folder icon and a trailing /. The working directory carries an orange tag, and in problem 8 the script carries a blue tag.

After you commit an answer, numbered dots on the tree show the route the path takes, and the same route is written out in words.

Lesson Plan

Grade level: Middle school and up (age 12+). Time: 10 to 15 minutes.

  1. Find the start. Look for the orange tag on the tree. A relative path starts there. A path that begins with / starts at the root instead.
  2. Walk the path. Go through the pieces from left to right. . stays where it is, .. moves up to the parent folder, and a name moves into that child.
  3. Commit. Click the file you reached, or No such file, and press Check. You get one attempt per problem.
  4. Compare. Read the steps the sim took and compare them with your own. Mastery is 7 of 8.
  5. Free trial. After problem 8, choose Free trial. Pick a working directory, type any path, and watch the steps update as you type. A path that ends at a folder is reported as a folder, not a file.
  6. Think about it. Problem 8 gives the same answer from every working directory. Why?

Specification

The learning objective, evidence of mastery and content for this MicroSim are specified in Chapter 1: Setting Up Python for Robotics.

References

  1. pathlib: Object-oriented filesystem paths - Python Standard Library documentation - The Path class, the parent attribute and the / operator used in problem 8.