C#如何找出U盘里文件夹名,以及删除相对应的文件夹名.exe的文件? C#如何找出U盘里文件夹名,以及删除相对应的文件夹名.exe的文件?比如说 U盘里有一个 文件夹 叫:新建文件夹 然后U盘病毒会自动生成一个 新建文件夹.exe 的文件如果实现找出这个新建文件夹.exe ?请大大们指教,如果分不够我再加! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 文件操作啊,String []files=Directory.GetFiles("U:");然后可以操作。 再u盘目录下。查找后缀是.exe的文件。然后删除。都是对文件进行的操作很容易的! 但是我不会,所以才来CSDN找大大帮忙的,希望帮忙下。我想看看方法 //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盘所在的目录就行了 //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啊? 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)); } } }楼主 看达到你的要求吧 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(); } 直接执行DOS命令我感觉不错! 写成个方法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(); } 对路径“e:\System Volume Information”的访问被拒绝。遍历子目录的时候出现这样的问题? 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:\"); DeleteExe(dir + "\\" + adirInfo[i].Name); -->DeleteExe(dir + adirInfo[i].Name); DataGridView的RowLeave事件 c# 算法找数,在线等 xml 中文乱码 DB2问题! MSN聊天记录,用什么工具打开看,格式不会乱呀? 问一个c#创建类库的问题,和vb有关 关于属性和字段的问题 TcpClient发送与TcpListener接收的数据长度问题 如何设置图象的分辨率? C#项目发布问题 关于终止方法调用的问题 C#: C/S结构下如何实现远程文件传输啊?
String []files=Directory.GetFiles("U:");
然后可以操作。
//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盘所在的目录就行了
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啊?
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));
}
}
}
楼主 看达到你的要求吧
{
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();
}
{
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();
}
{
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:\");