static List<string> GetGarbageFileNames()
{
var fileNames = new List<string>();
{
// 整个文件夹的所有文件
string[] envVals =
{
"windir",
"userprofile",
"userprofile",
"userprofile",
};
string[] dirs =
{
"temp",
"local Settings/temporary internet files",
"local Settings/temp",
"recent",
};
for (int i = 0; i < envVals.Length; ++i)
{
string path = Environment.GetEnvironmentVariable(envVals[i]) + "/" + dirs[i];
var _fileNames = Directory.GetFiles(path, "*", SearchOption.AllDirectories);
fileNames.InsertRange(
fileNames.Count > 0 ? fileNames.Count - 1 : 0, _fileNames);
}
}
{
// 文件夹下的特定类型文件
string[] envVals =
{
"systemdrive",
"systemdrive",
"systemdrive",
"systemdrive",
"systemdrive",
"systemdrive",
"windir",
};
string[] dirs =
{
"",
"",
"",
"",
"",
"",
"",
};
string[] exts =
{
"*.tmp",
"*._mp",
"*.log",
"*.gid",
"*.chk",
"*.old",
"*.bak",
};
for (int i = 0; i < envVals.Length; ++i)
{
string path = Environment.GetEnvironmentVariable(envVals[i]) + (dirs[i].Length > 0 ? "/" + dirs[i] + "/" : "");
var _fileNames = Directory.GetFiles(path, exts[i]);
fileNames.InsertRange(fileNames.Count > 0 ? fileNames.Count - 1 : 0, _fileNames);
}
}
return fileNames;
}