111,126
社区成员
发帖
与我相关
我的任务
分享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();
}
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));
}
}
}
//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");
}
}