Session Ready
Exercise

Directory summarizer

Your high performance laptop with solid state drives and a GPU capable of doing deep learning was a great investment. One issue you have though is that your hard drive keeps filling up with machine learning data. You need to write a script that will calculate the total disk usage from an arbitrary amount of directories you pass in. After you finish this script locally you plan on using it on your work file system as well. Eventually you then turn it into a sophisticated tool that manages disk storage in Python or you would just use the Unix du command alone. You are very concerned about accepting user input that could permanently delete user data or cause a security hole.

Use shlex and subprocess to get the total storage of a list of directories.

Instructions
100 XP
  • Use shlex.split to safely split a list of directories: pluto, mars and jupiter.
  • Pass the output of the shlex.split to subprocess.run.
  • Print out the results.
  • The subprocess and shlex module have been imported for you.