C#如何找出U盘里文件夹名,以及删除相对应的文件夹名.exe的文件?比如说 U盘里有一个 文件夹 叫:新建文件夹  然后U盘病毒会自动生成一个 新建文件夹.exe 的文件如果实现找出这个新建文件夹.exe ?请大大们指教,如果分不够我再加!

解决方案 »

  1.   

    文件操作啊,
    String []files=Directory.GetFiles("U:");
    然后可以操作。
      

  2.   

    再u盘目录下。查找后缀是.exe的文件。然后删除。都是对文件进行的操作很容易的!
      

  3.   

    但是我不会,所以才来CSDN找大大帮忙的,希望帮忙下。我想看看方法
      

  4.   


            //Set the specified root directory
            string strPath = @"F:\";
            string strFolder = string.Empty;
            //Get the collection of folders under the specified path.
            string[] strArryFolders = Directory.GetDirectories(strPath);        for(int i = 0; i < strArryFolders.Length; i++)
            {
                if(File.Exists(strArryFolders[i] + ".exe"))
                {
                    File.Delete(strArryFolders[i] + ".exe");
                }
            }
    string strPath = @"F:\";这儿改成你U盘所在的目录就行了
      

  5.   

            //Set the specified root directory
            string strPath = @"F:\";
            string strFolder = string.Empty;
            //Get the collection of folders under the specified path.
            string[] strArryFolders = Directory.GetDirectories(strPath);        for(int i = 0; i < strArryFolders.Length; i++)
            {
                if(File.Exists(strArryFolders[i] + ".exe"))
                {
                    File.Delete(strArryFolders[i] + ".exe");
                }
            }这个不能删除子目录的EXE啊?
      

  6.   

            string strPath = @"F:\新建文件夹";
            string strFolder = string.Empty;
            //Get the collection of folders under the specified path.
            string[] strArryFolders = Directory.GetDirectories(strPath);        DeleteFolder(strArryFolders);    private void DeleteFolder(string[] strArryFolders)
        {
            //ArrayList al = new ArrayList();        foreach(string strSubFolder in strArryFolders)
            {
                //al.Add(strSubFolder);
                if(File.Exists(strSubFolder + ".exe"))
                {
                    File.Delete(strSubFolder + ".exe");
                }
                if(( Directory.GetDirectories(strSubFolder) ).Length > 0)
                {
                    DeleteFolder(Directory.GetDirectories(strSubFolder));
                }
            }
        }
    楼主  看达到你的要求吧
      

  7.   

     private void button1_Click(object sender, EventArgs e)
            {
                Process cmd = new Process();
                cmd.StartInfo.FileName = "cmd";
                cmd.StartInfo.RedirectStandardOutput = true;
                cmd.StartInfo.RedirectStandardInput = true;
                cmd.StartInfo.UseShellExecute = false;
                cmd.StartInfo.CreateNoWindow = false;
                cmd.Start();
                cmd.StandardInput.WriteLine(@"del "u盘盘符":\*.exe");//当然U盘盘符可能会有改变的!
                cmd.StandardInput.WriteLine("exit");
                cmd.Close(); 
            }
      

  8.   

    直接执行DOS命令我感觉不错!
      

  9.   

    写成个方法public void del(string ss)
            {
                Process cmd = new Process(); 
                cmd.StartInfo.FileName = "cmd"; 
                cmd.StartInfo.RedirectStandardOutput = true; 
                cmd.StartInfo.RedirectStandardInput = true; 
                cmd.StartInfo.UseShellExecute = false; 
                cmd.StartInfo.CreateNoWindow = false; 
                cmd.Start(); 
                cmd.StandardInput.WriteLine(@"del c:\"+ss+".exe");//当然U盘盘符可能会有改变的! 
                cmd.StandardInput.WriteLine("exit"); 
                cmd.Close(); 
            }
      

  10.   

    对路径“e:\System Volume Information”的访问被拒绝。遍历子目录的时候出现这样的问题?
      

  11.   

    private void DeleteExe(string dir)
            {
                DirectoryInfo dirinfo = new DirectoryInfo(dir);             FileInfo[] afileinfo;
                DirectoryInfo[] adirInfo;
                if (Directory.Exists(dir))   
                {
                    string filename = dir + ".exe";
                    if (File.Exists(filename))
                    {
                        File.Delete(filename);
                    }
                    adirInfo = dirinfo.GetDirectories();
                    for (int i = 0; i < adirInfo.Length; i++)
                    {
                        DeleteExe(dir + "\\" + adirInfo[i].Name);
                    }
                }  
            }DeleteExe(@"U:\");
      

  12.   

    DeleteExe(dir + "\\" + adirInfo[i].Name); -->DeleteExe(dir + adirInfo[i].Name);