这是一个小型应用程序,它使用深度采样来查找任何磁盘或目录中的肿瘤。它遍历目录树两次,一次是测量它,第二次是打印出目录下 20 个“随机”字节的路径。
void walk(string sDir, int iPass, int64& n, int64& n1, int64 step){
foreach(string sSubDir in sDir){
walk(sDir + "/" + sSubDir, iPass, n, n1, step);
}
foreach(string sFile in sDir){
string sPath = sDir + "/" + sFile;
int64 len = File.Size(sPath);
if (iPass == 2){
while(n1 <= n+len){
print sPath;
n1 += step;
}
}
n += len;
}
}
void dscan(){
int64 n = 0, n1 = 0, step = 0;
// pass 1, measure
walk(".", 1, n, n1);
print n;
// pass 2, print
step = n/20; n1 = step/2; n = 0;
walk(".", 2, n, n1);
print n;
}
我的 Program Files 目录的输出如下所示:
7,908,634,694
.\ArcSoft\PhotoStudio 2000\Samples\3.jpg
.\Common Files\Java\Update\Base Images\j2re1.4.2-b28\core1.zip
.\Common Files\Wise Installation Wizard\WISDED53B0BB67C4244AE6AD6FD3C28D1EF_7_0_2_7.MSI
.\Insightful\splus62\java\jre\lib\jaws.jar
.\Intel\Compiler\Fortran\9.1\em64t\bin\tselect.exe
.\Intel\Download\IntelFortranProCompiler91\Compiler\Itanium\Data1.cab
.\Intel\MKL\8.0.1\em64t\bin\mkl_lapack32.dll
.\Java\jre1.6.0\bin\client\classes.jsa
.\Microsoft SQL Server\90\Setup Bootstrap\sqlsval.dll
.\Microsoft Visual Studio\DF98\DOC\TAPI.CHM
.\Microsoft Visual Studio .NET 2003\CompactFrameworkSDK\v1.0.5000\Windows CE\sqlce20sql2ksp1.exe
.\Microsoft Visual Studio .NET 2003\SDK\v1.1\Tool Developers Guide\docs\Partition II Metadata.doc
.\Microsoft Visual Studio .NET 2003\Visual Studio .NET Enterprise Architect 2003 - English\Logs\VSMsiLog0A34.txt
.\Microsoft Visual Studio 8\Microsoft Visual Studio 2005 Professional Edition - ENU\Logs\VSMsiLog1A9E.txt
.\Microsoft Visual Studio 8\SmartDevices\SDK\CompactFramework\2.0\v2.0\WindowsCE\wce500\mipsiv\NETCFv2.wce5.mipsiv.cab
.\Microsoft Visual Studio 8\VC\ce\atlmfc\lib\armv4i\UafxcW.lib
.\Microsoft Visual Studio 8\VC\ce\Dll\mipsii\mfc80ud.pdb
.\Movie Maker\MUI\0409\moviemk.chm
.\TheCompany\TheProduct\docs\TheProduct User's Guide.pdf
.\VNI\CTT6.0\help\StatV1.pdf
7,908,634,694
它告诉我目录是7.9gb,其中
- ~15% 用于英特尔 Fortran 编译器
- ~15% 用于 VS .NET 2003
- ~20% 用于 VS 8
询问这些是否可以卸载很简单。
它还讲述了分布在文件系统中的文件类型,但综合起来代表了节省空间的机会:
- ~15% 大约用于 .cab 和 .MSI 文件
- ~10% 大致用于记录文本文件
它还显示了很多其他我可能不需要的东西,比如“SmartDevices”和“ce”支持(~15%)。
这确实需要线性时间,但不必经常这样做。
它发现的例子:
- 在许多已保存的代码存储库中备份 DLL 副本,真的需要保存
- 服务器上某个不知名目录下某人硬盘的备份副本
- 大量临时 Internet 文件
- 古老的文档和帮助文件早已不再需要