2012 Scripting Games Beginner Event 3: Create a File in a Folder

 2012 Scripting Games badge

Summary: Beginner Event 3 of the 2012 Scripting Games requires you to create a file in a folder that may or may not exist.

About this event



Date of Event

4/4/2012 12:01 AM

Due Date

4/11/2012 12:01 AM


Event scenario

You are a local user, and you want to document the processes that are running on your computer. You decide that you would like to list the name and process ID of each process running on your computer. You want to save this information in a nested folder. Because you use a number of different computers, you are never certain that the folder will exist. The folder is nested off the root directory in the following location:


The following image illustrates the folder/file arrangement.

Image of folder

The image that follows illustrates the contents of the Process3.txt file.

Image of command output

Design points

  • If you do not have permission off the root, create the nested folder where you have permissions. Keep in mind that the folder MUST be nested, and it must be named 2012sg\event3. The file must be named Process3.txt.
  • Your code should check to see if the folder exists. If it does not exist, it should be created, and then the Process3.txt file should be created. If it does exist, the Process3.txt file should be created.
  • Your script should not generate errors (that are ignored), even if it does create the Process3.txt.
  • Your script does not have to have command-line parameters, but if you want to include them (with a default path that solves this problem), you will gather additional points.
  • If you choose to add command-line parameters, you should include comment-based Help that describes the parameters, and a sample example of use.

2012 Scripting Games links

2012 Scripting Games: All Links on One Page

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, 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 

Comments (22)

  1. mredwilson says:

    @Chris Seiter … this is a great point. But for this scenario, your submission can assume that the c: drive is the system drive. I do not want the scripts to have to be TOO complicated, or to have to do TOO much error checking.

  2. mredwilson says:

    @Michael Moore, @Mr. Killian I did not want you to have to do the permission check because as @Timo points out I do not want the event to be too hard for beginners. If this were an advanced event, then I would require the permission check, and also require the check for determining where systemroot resides. But this IS a beginner event, and I do NOT want it to be too difficult.

  3. mredwilson says:

    @Paul Cunningham if the file exists it should be appended to … but if you choose to overwrite the file that is fine as well because I did not specify that in the design guidelines.

  4. mredwilson says:

    @Kyle the event specifically talks about checking for the folder, but does not specifically mention the file. If the file exists, you can either overwrite it or append to it … that is a design point for you to make.

  5. mredwilson says:

    @Ratty67 You are right. The scenario does not REQUIRE command line arguments, but one might be added, for example you might want to include a parameter that allows you to select where to store the output file. Or to type in a custom name for the file. This would permit using the code somewhere else for some other purpose.

  6. mredwilson says:

    @Killian Yes, it is safe to assume (for this scenario) that the system drive is always c:. The command line parameter portion, could be as simple, as having a parameter that accepts a path for where to create the log, or a name for the log itself. This would allow you to use this script in other scenarios. But if you do this, keep in mind your submission MUST have default values that meet the needs of the scenario.

  7. mredwilson says:

    @Michael Moore no. You do not need to check for permissions off the root. If in your testing you do not have permission to the root, then use your MYDOCUMENTS folder. In fact, there is a great Scripting Wife article that talks about how to do this.

  8. mredwilson says:

    @Timo @DawnV I put the line in there about if you do not have permission, simply because I realise that some people may be running with NON-ADMIN rights, and not have permission to the root. Therefore I did not want them to think they could not do the event. It is not my intention to clutter a beginner event with permission checks etc.

  9. Anonymous says:

    Thanks @Chris.  Amended Script without that assumption now.

    @Michael I'd be interested to know the answer to this too.  I'm not sure if the Design Point means the script must check for permissions or that it is acceptable for us to make the script write elsewhere if we don't have access to the root of the system drive.  I figure the former is more likely but don't want to work on how to do that until it gets confirmed.  🙂

  10. Killian says:

    I've put something together that does this fairly well I think but am thrown off a little by the Design Point stating extra points for Command Line Parameters.  Not sure what is meant by this?  Is it safe to assume the systemdrive is always 'C:'?

  11. Michael Moore says:

    If you do not have permission off the root, create the nested folder where you have permissions.

    For this one does this mean we need the script to check to see if permissions are there and then write to an alternate location, or is this something we should determine before writing the script?

  12. Michael Moore says:

    @Mr Killian Yeah, it seems odd to me that the script could be written to be inconsistent.  On one computer your ID could have access to the root drive, on another it may not.  As the person running the script I would not want to be guessing on each system where the file went.  In this scenario I'm not quite sure what to provide for this part.

  13. timo says:

    I think a permission check would be a little bit to difficult for Day 3 in the beginner class 😉

    As i understand it, if there is no access to C:, just created it on drive d: or elsewhere, as long as the structure says …2012sgevent3

  14. DawnV says:

    @Timo  I understand it the same as you. I'll wait for clarification just to be sure 🙂

  15. If the Process3.txt file exists do you want it appended or overwritten?

  16. chris seiter says:

    Got so giddy about submitting that I forgot to change the event.  My Beginner 3 is in Advanced 1.

  17. Kyle says:

    From the way this is worded, it can be assumed that the file does not exist therefor we do not need to check for it?

  18. ratty67 says:

    I wonder if I am missing something here. I do not see the need for any command line arguments. As the scenario reads, there is no choice that is required to be made. If we have access to C: then we MUST create a file named Process3.txt in the subfolder 2012SGevent3. Where is the value of command line arguments here ?

  19. james says:

    excuse me, I have a question. I submit wrong script in advan event 3, it should be submit in beginner event 3. and i have been submitted it in beginner event 3 channel. but could i submit the other verison script in advan event 3 again?

  20. Zak Humphries says:

    Accidently submitted it to Advanced 3. Sorry 🙁

  21. @James

    @Zak Humphries

    Please email to scripter@Microsoft.com and give him the full URL of the exact submission that is wrong… for example this is the URL for my event one.

    Ed will then check with Joel about changing the category.

    @Everyone.  Please double check your category and event this is a manual process for Joel to correct the submission and can only be done if he is not overwhelmed with them.

Skip to main content