2012 Scripting Games Advanced Event 4: Determine Folder Space
Summary: In Advanced Event 4, you are required to determine which folders consume the most space.
About this event
Date of Event
4/5/2012 12:01 AM
4/12/2012 12:01 AM
You are a freelance journalist, and as a result, you travel to various locations around the world in search of the latest and greatest news. You create a folder for each story you work on. The folder holds the Word document that contains the basic story, numerous picture files, and an Excel spreadsheet that details location, contacts, expenses, and publications that have been offered the story. If you recast a story for additional markets, that story appears in a subfolder. All of the folders are grouped by year.
The folder arrangement works great, and it simplifies data backup, but the problem is that your laptop appears to be running out of disk space. It might be possible to archive story folders from previous years, but the problem with that idea is that you often like to use pictures that were not published in the earlier stories in later articles. Therefore, a simple archive by date might not be the most effective solution.
You decide to write a Windows PowerShell script that reports folder size so that you can make a more informed decision to reclaim the most disk space and yet maintain access to the most useful content from previous years. An appropriate output is shown in the image that follows.
- You do not need to check for admin rights in this script. Assume you have permissions to access the folders you want to check.
- You should return a custom object to permit further analysis and sorting.
- You should display folder size in the most appropriate unit of measurement. Therefore, do not report 1073741824 bytes when you could just as easily report 1 Gigabyte.
- You should report sizes accurate to two decimal places. Do not report 1.23456794 bytes; instead, round it to 1.23 bytes.
- You should accept a command-line parameter that permits you to supply a specific folder. You should recurse by default.
- You should consider adding comment-based Help.
- You should consider creating reusable functions as part of this script.
2012 Scripting Games links
I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at firstname.lastname@example.org, or post your questions on the Official Scripting Guys Forum. Good luck as you compete in this year’s Scripting Games. We wish you well.
Ed Wilson, Microsoft Scripting Guy