递归--遍历文件夹

因为有些脚本小子会注意到俺的网站,向网站文件夹里面搞一些乱七八糟的东西,或者传个木马上来,如果这样的话,俺会丢饭碗,会破产,所以俺用递归的方法写了个功能,来看看文件有没有给别人改动了,或者有不该存在的文件给传上来了,加密算法不写,因为怕人破解,只写遍历文件夹:

public static void SetAllSafeCode(string path)
{
path += "\\";
//if there is no Directories, only files exists
if (Directory.GetDirectories(path).Length == 0)
{
//check all files of this path
foreach (string name in Directory.GetFiles(path))
{
//initialize an safe string object
SafeString ss = new SafeString();
//set property of this object
ss.FileName = name.Substring(path.Length);
ss.FilePath = name;
ss.Code = GetSafeCode(GetFileContent(name));
//store this object into list
ssList.Add(ss);
}
return;
}
else//if this path contains Directory
{
//check all directory of this path
foreach (string name in Directory.GetDirectories(path))
{
SetAllSafeCode(name);//Recursion 递归
}
//check all files of this path
foreach (string name in Directory.GetFiles(path))
{
SafeString ss = new SafeString();
ss.FileName = name.Substring(path.Length);
ss.FilePath = name;
ss.Code = GetSafeCode(GetFileContent(name));
ssList.Add(ss);
}
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值