Exercise: Restoring Files and Directories

Test your coding skills on restoring files and directories.


Exercise: Restoring files and directories

In this exercise, your challenge is to expand the walk tool you developed previously to restore files previously archived with the tool.

Problem statement

The current version of the walk tool has an option to archive files in compressed gzip format.

Coding challenge

Create a companion tool for walk that restores the archived files in case they’re needed again. Recreate the original directory by using the same approach you used to create the destination directory in the archiveFile() function. Then use the gzip.Reader type from the compress/gzip package to uncompress the archive files.

Start from the walk implementation at end of this Chapter. Take some time to figure out the smartest way to solve this problem. The new restoreFile will be similar to the one you use to archive files, so it’s a good starting point. Make sure you add a new flag restore in the main.go, allowing the user to choose which directory to restore the files to. You can use the strings package to deal with the .gz extension of the compressed files.

Run the following command to restore the files:

Get hands-on with 1200+ tech skills courses.