C#如何找出U盘里文件夹名,以及删除相对应的文件夹名.exe的文件?

paigus 2009-03-26 01:38:41
C#如何找出U盘里文件夹名,以及删除相对应的文件夹名.exe的文件?

比如说 U盘里有一个 文件夹 叫:新建文件夹

然后U盘病毒会自动生成一个 新建文件夹.exe 的文件

如果实现找出这个新建文件夹.exe ?请大大们指教,如果分不够我再加!
...全文
545 26 打赏 收藏 转发到动态 举报
写回复
用AI写文章
26 条回复
切换为时间正序
请发表友善的回复…
发表回复
gaogao0603 2009-03-26
  • 打赏
  • 举报
回复
有相应的软件啊!
hxxxs 2009-03-26
  • 打赏
  • 举报
回复
DeleteExe(dir + "\\" + adirInfo[i].Name); -->DeleteExe(dir + adirInfo[i].Name);
hxxxs 2009-03-26
  • 打赏
  • 举报
回复
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:\");
贫僧又回来了 2009-03-26
  • 打赏
  • 举报
回复
[Quote=引用 21 楼 paigus 的回复:]
对路径“e:\System Volume Information”的访问被拒绝。

遍历子目录的时候出现这样的问题?
[/Quote]
这是系统受保护文件!
paigus 2009-03-26
  • 打赏
  • 举报
回复
十分感谢了。。。
paigus 2009-03-26
  • 打赏
  • 举报
回复
对路径“e:\System Volume Information”的访问被拒绝。

遍历子目录的时候出现这样的问题?
贫僧又回来了 2009-03-26
  • 打赏
  • 举报
回复
写成个方法

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();
}
贫僧又回来了 2009-03-26
  • 打赏
  • 举报
回复
直接执行DOS命令我感觉不错!
贫僧又回来了 2009-03-26
  • 打赏
  • 举报
回复
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();
}
jie3614 2009-03-26
  • 打赏
  • 举报
回复


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));
}
}
}


楼主 看达到你的要求吧
paigus 2009-03-26
  • 打赏
  • 举报
回复
up
soaringbird 2009-03-26
  • 打赏
  • 举报
回复
有专门杀这个病毒的工具
jie3614 2009-03-26
  • 打赏
  • 举报
回复
哥们 偶暂时没想出什么好办法 帮你顶一下
paigus 2009-03-26
  • 打赏
  • 举报
回复
有没有人啊
paigus 2009-03-26
  • 打赏
  • 举报
回复
up
paigus 2009-03-26
  • 打赏
  • 举报
回复
怎么遍历呢?
zhoulehua 2009-03-26
  • 打赏
  • 举报
回复
顶起来了。
jie3614 2009-03-26
  • 打赏
  • 举报
回复
哦 需要要遍历
paigus 2009-03-26
  • 打赏
  • 举报
回复
//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啊?
jie3614 2009-03-26
  • 打赏
  • 举报
回复

//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盘所在的目录就行了
加载更多回复(6)

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧