Skip to content

Instantly share code, notes, and snippets.

@yutopio
Created September 3, 2015 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yutopio/1dce83bd17da44e611b0 to your computer and use it in GitHub Desktop.
Save yutopio/1dce83bd17da44e611b0 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.Linq;
static class Program
{
static void Main(string[] args)
{
if (args.Length != 1) return;
var path = args[0];
var searchPattern = "*.log";
var output = Path.GetTempFileName();
using (var fs = new FileStream(output, FileMode.Create, FileAccess.Write))
using (var sw = new StreamWriter(fs))
{
var dir = new DirectoryInfo(path);
foreach (var d in dir.GetDirectories())
{
IEnumerable<string> query = null;
try { query = Search(d, searchPattern); }
catch (UnauthorizedAccessException) { continue; }
var files = query.ToList();
sw.WriteLine("Directory: {0} - {1}", d.Name, files.Count);
foreach (var f in files)
sw.WriteLine(f);
sw.WriteLine();
}
}
Process.Start("notepad", output);
}
static IEnumerable<string> Search(DirectoryInfo dir, string searchPattern)
{
IEnumerable<string> ret = new string[0];
foreach (var d in dir.GetDirectories())
{
try { ret = ret.Union(Search(d, searchPattern)); }
catch (UnauthorizedAccessException) { }
}
ret = ret.Union(dir.GetFiles(searchPattern).Select(x => x.FullName));
return ret;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment