如何使用功能搜索路径 [英] How to search path with function

查看:70
本文介绍了如何使用功能搜索路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我制作了一个搜索路径的工具(例如搜索C:\ Windows \ *.*以及子文件夹中的任何文件,例如C:\ Windows \ System32 \ *.*)和任何文件找到它的MD5,当发现MD5等于恶意软件MD5时,将其删除(这是小型清除工具)

I made a tool to search path (for exambel it search C:\Windows\*.* and any file in sub folder like C:\Windows\System32\*.*)  and any file find its MD5, and when find MD5 equal malware MD5 it delete it (it is small removal tool)

问题是在子文件夹中找到文件,工具在搜索根文件夹中(在C:\ Windows中找到文件的MD5,但在System32中找不到文件的MD5)

the problem is finding files in sub folders ,the tool search root folder (it is find MD5 for files in C:\Windows but it isn't find MD5 for files in System32)

任何人都可以帮助我(项目,MSDN,网站等)

So can any help me (Projects,MSDN,Website,...etc)

谢谢

推荐答案

此代码将递归应用目录树提供的Action< FileInfo>到找到的每个文件:

This code will recurse a tree of directories applying the supplied Action<FileInfo> to each file it finds:


    static void Main(string[] args)
    {
      var root = new DirectoryInfo("c:\\windows");
      Program.RecurseDir(root, f => Console.WriteLine(f.Name));
    }

    private static void RecurseDir(DirectoryInfo dir, Action<FileInfo> fileAction)
    {
      foreach (FileInfo file in dir.GetFiles())
      {
        fileAction(file);
      }

      foreach(DirectoryInfo subDir in dir.GetDirectories())
      {
        Program.RecurseDir(subDir, fileAction);
      }
    }


这篇关于如何使用功能搜索路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆