Skip to content

Instantly share code, notes, and snippets.

@ikkentim
Created April 26, 2016 19:36
Show Gist options
  • Save ikkentim/dd604b07d02f1f38e8b7a7c411f1faa0 to your computer and use it in GitHub Desktop.
Save ikkentim/dd604b07d02f1f38e8b7a7c411f1faa0 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication7
{
internal class Program
{
private static void Main(string[] args)
{
var sw = new Stopwatch();
sw.Start();
foreach (var p in GetSteamAppsFolders())
Console.WriteLine(p);
sw.Stop();
Console.WriteLine($"Done. Took {sw.Elapsed}");
Console.ReadLine();
}
private static IEnumerable<string> GetSteamAppsFolders()
{
return DriveInfo.GetDrives()
.Where(d => d.DriveType == DriveType.Fixed)
.SelectMany(d => GetSteamAppsFolders(d.RootDirectory.FullName, 0));
}
private static string[] IgnoredFolders =
{
@"C:\Users",
@"C:\Windows",
@"C:\UserData",
};
private static IEnumerable<string> GetSteamAppsFolders(string path, int depth)
{
string[] directories;
try
{
directories = Directory.GetDirectories(path);
}
catch
{
yield break;
}
//Console.WriteLine(path);
foreach (var directory in directories.Except(IgnoredFolders))
{
if (Path.GetFileName(directory) == "SteamApps")
yield return directory;
if(depth < 4)
foreach (var r in GetSteamAppsFolders(directory, depth + 1))
yield return r;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment