getSteam

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Management;
using System.IO;
using System.Diagnostics;


//获取steam的路径
string getSteam()
{
string sSteamDir = "";
//获取本地磁盘
DriveInfo[] aDr = DriveInfo.GetDrives();
foreach (DriveInfo dd in aDr)
{
if (dd.DriveType == DriveType.Fixed)
{

sSteamDir = isSteam(dd.ToString().ToLower());
if (sSteamDir != null)
{
return sSteamDir;
}
}
}
return null;
}
string isSteam(string sDir)
{
string steam = "";
DirectoryInfo dDir = new DirectoryInfo(sDir);
if ((steam = isExists(sDir)) == null)
{
foreach (DirectoryInfo d in dDir.GetDirectories())
{
if ((steam = isExists(sDir + d.ToString())) != null)
{
return steam;
}
}

}
return null;


}
string isExists(string d)
{
string steam = d + "\steam".ToLower();

if (Directory.Exists(steam))
{
return steam;
}
return null;
}

原文地址:https://www.cnblogs.com/bingxing/p/8601321.html