.net定期删除一文件夹下的所有文件,并调用相关exe
2011-03-25 11:21
375 查看
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.IO; namespace DeleteFile { /// <summary> /// /bin/Debug下有2个文件,一个保存每次删除文件夹的日期,另一个保存被调用的exe路径 /// /// 此代码实现的功能:每6天删除文件夹下的所有文件【直接删除文件夹】,然后创建此文件夹,并且调用相关exe,如果时间不到,则只调用exe /// </summary> class Program { //要删除的目录路径 string path = "E://cap"; //保存日期的文件目录 string debugPath = AppDomain.CurrentDomain.BaseDirectory; static void Main(string[] args) { new Program().invoke(); } void invoke() { //获取保存日期的文件的路径 string saveDatePath = debugPath + "saveDateFile.txt"; //获取保存被调用的exe的路径 string exePath = File.ReadAllText(debugPath + "saveExe.txt"); //获取当前日期 DateTime nowDate = DateTime.Today; //获取上次日期 string last = File.ReadAllText(saveDatePath); Console.WriteLine("当前日期:" + nowDate.ToShortDateString() + "/n上次保存的日期: " + last); DateTime lastDate = Convert.ToDateTime(last); //计算差值 TimeSpan timeSpan = nowDate - lastDate; double minus = timeSpan.TotalDays; Console.WriteLine("差值: " + minus); if (minus >= 6) { Console.WriteLine("一个星期。。删除...."); if (Directory.Exists(path)) { Directory.Delete(path, true); //此文件夹下的文件约100G Thread.Sleep(60* 1000); Directory.CreateDirectory(path); File.WriteAllText(saveDatePath, nowDate.ToShortDateString()); Console.WriteLine("新日期已成功存入文件中..."); System.Diagnostics.Process.Start(exePath); } else { Console.WriteLine("E://cap目录不存在..."); } } else { Thread.Sleep(5 * 1000); System.Diagnostics.Process.Start(exePath); } } } }
相关文章推荐
- .net定期删除一文件夹下的所有文件,并调用相关exe 分类: .NET 2011-03-25 11:21 1832人阅读 评论(0) 收藏
- .net 删除文件夹下的所有文件但不删除目录
- 删除文件夹(递归调用删除所有子文件夹及文件)
- .net删除文件夹中所有的文件
- Java中通过递归调用删除文件夹下所有文件
- java 定期将指定文件夹下的所有文件打包+删除
- java通过递归调用删除文件夹下所有文件
- Java中通过递归调用删除文件夹下所有文件
- C#复制或删除文件夹(及文件夹下所有子文件夹和文件)、获取文件所在文件夹、二进制读取文件相关
- 删除文件夹(非空目录)及其中所有文件
- 如何删除文件夹(文件)里面的所有数据
- Java删除文件夹下所有的文件和文件夹
- 删除Document文件夹下所有文件的方式
- C# - 递归删除某一路径下的所有文件和文件夹
- Python定期删除文件、整理文件夹
- <转>删除文件夹下所有的.svn文件
- mac 删除文件夹里所有的.svn文件
- 遍历删除当前文件夹中所有 .svn 的文件
- python删除文件夹及文件夹内所有文件
- php删除/复制文件夹及其文件夹下所有文件