Created
September 3, 2015 06:23
-
-
Save yutopio/1dce83bd17da44e611b0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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