Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

File Drills

exercises/file_drills.livemd

File Drills

Mix.install([
  {:jason, "~> 1.4"},
  {:kino, "~> 0.9", override: true},
  {:youtube, github: "brooklinjazz/youtube"},
  {:hidden_cell, github: "brooklinjazz/hidden_cell"}
])

Navigation

Home Report An Issue Stream DrillsSave Game

File Drills

Drills help you develop familiarity and muscle memory with syntax through repeated exercises. Unlike usual problems, Drills are not intended to develop problem solving skills, they are purely for developing comfort and speed.

This set of drills is for the File module. Follow the instructions for each drill and complete them as quickly as you can.

File

Use File.ls/1 to list all of the files/folders in the current path.

Use File.ls/1 to list all of the files/folders in the parent directory of the current path.

Use File.mkdir/1 to create a directory called drills.

Use File.dir?/2 to check that drills is a folder.

Use File.write/3 to create an empty file called drills.txt.

Use File.exists?/2 to check that the drills.txt file exists.

Use File.dir?/2 to check that drills.txt is not a folder.

Use File.write/3 to create a filed called hello.txt with the content "world".

Use File.read/1 to read the content of the hello.txt file.

Use File.write/3 to create an empty file in the drills folder you previously created.

Use File.write/3 to create an error/no_entity.txt file that should return {:error, :enoent} because the error folder does not exist.

Use File.write/3 to create a file multi-line.txt with a multi-line string.

multiline_string = """
line 1
line 2
line 3
line 4
line 5
"""

Use File.read/1 to read multi-line.txt.

Use File.stream!/3 to read each line of multi-line.txt and convert it to a list of lines using Enum.to_list/1.

Use File.stream!/3 and Stream.filter/2 to filter in lines from multi-line.txt that contain numbers less than 3.

Use File.write/3 to re-write multi-line.txt with only the filtered lines.

"""
line 1
line 2
line 3
"""

Use File.open/2, IO.binread/2, and File.close/1 to read the first line of multi-line.txt. Print the value.

Use File.mkdir_p/1 to create:

  • "parent/sub_a/"
  • "parent/sub_b"
  • "parent/sub_c"

Use File.write!/3 to create six empty files:

  • "parent/sub_a/file.txt"
  • "parent/sub_a/file"
  • "parent/sub_b/file.txt"
  • "parent/sub_b/file"
  • "parent/sub_c/file.txt"
  • "parent/sub_c/file"

Use File.ls!/1 to find all of the files/folders inside of the parent folder.

Path

Use Path.join/2 to join "/parent/" and "/child/"

Use Path.join/2 to join "parent" and "child"

Use Path.join/2 to join "folder" and "file.txt".

Use Path.absname/1 to convert the current path "." to an absolute path.

Use Path.dirname/1 to find the directory name of "folder/subfolder/file.txt"

Use Path.dirname/1 to find the directory name of "file.txt".

Use Path.wildcard/2 to find all files in a nested folder "parent/*" that end in a .txt extension. You should see your three file.txt files created earlier.

Use File.rm_rf/1 to delete all folders created by this exercise.

CAUTION: DO NOT DELETE IMPORTANT FILES ON YOUR COMPUTER.

Use File.rm/1 to delete any remaining files created by this exercise.

CAUTION: DO NOT DELETE IMPORTANT FILES ON YOUR COMPUTER.

Commit Your Progress

DockYard Academy now recommends you use the latest Release rather than forking or cloning our repository.

Run git status to ensure there are no undesirable changes. Then run the following in your command line from the curriculum folder to commit your progress.

$ git add .
$ git commit -m "finish File Drills exercise"
$ git push

We’re proud to offer our open-source curriculum free of charge for anyone to learn from at their own pace.

We also offer a paid course where you can learn from an instructor alongside a cohort of your peers. We will accept applications for the June-August 2023 cohort soon.

Navigation

Home Report An Issue Stream DrillsSave Game