Skip to content

Commit

Permalink
Add capability to create the directory if it doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
caschw committed Jan 9, 2015
1 parent 9b02a98 commit deebf6a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ApplicationLister/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using ApplicationLister.Extensions;
using ApplicationLister.Lister;
Expand All @@ -21,9 +22,16 @@ private static void Main(string[] args)
registryApps.AddRange(managementApps);
registryApps = registryApps.RemoveDuplicateResults();

var path = @"C:\test\InstalledPrograms.txt";

if(!Directory.Exists(Path.GetDirectoryName(path)))
{
Directory.CreateDirectory(Path.GetDirectoryName(path));
}

// Output app list to console and file
var i = 0;
using (var file = new System.IO.StreamWriter(@"C:\test\InstalledPrograms.txt"))
using (var file = new System.IO.StreamWriter(path))
{
foreach (IDictionary<string, object> application in registryApps.OrderBy(x => (x as IDictionary<string, object>)["DisplayName"]))
{
Expand Down

0 comments on commit deebf6a

Please sign in to comment.