基本信息
源码名称:c# 删除指定日期的log文件 示例源码下载
源码大小:0.05M
文件格式:.rar
开发语言:C#
更新时间:2016-11-07
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace Delete_Logs
{
public partial class Deletelogs : Form
{
public Deletelogs()
{
InitializeComponent();
}
private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
{
tbdeleteday.Text = monthCalendar1.SelectionStart.ToShortDateString();
}
private void btdelete_Click(object sender, EventArgs e)
{
int deleteyear = monthCalendar1.SelectionStart.Year;
int deletemonth = monthCalendar1.SelectionStart.Month;
int deleteday = monthCalendar1.SelectionStart.Day;
DirectoryInfo folder = new DirectoryInfo("d:\\logs\\");
FileInfo[] files = folder.GetFiles("*.log.*");
DateTime date = new DateTime();
foreach (FileInfo info in files)
{
if (DateTime.TryParse(info.Name.Substring(0, 10), out date))
{
if (date.Date < monthCalendar1.SelectionStart.Date)
{
info.Delete();
}
}
}
//foreach (FileInfo info in files)
//{
// if(info.CreationTime<monthCalendar1.SelectionStart)
// {
// info.Delete();
// }
//}
//for (int i = 2015; i < deleteyear; i )
//{
for (int l = 0; l < 6; l )
{
DirectoryInfo Bayno = new DirectoryInfo("d:\\CTSDatas\\Bay" (l 1).ToString());
DirectoryInfo[] monthdelcts = Bayno.GetDirectories();
foreach (DirectoryInfo info in monthdelcts)
{
if (DateTime.TryParse(info.Name.Substring(0, 7), out date))
{
if (date.Month < monthCalendar1.SelectionStart.Month)
{
info.Delete(true);
}
}
}
DirectoryInfo monthcts = new DirectoryInfo("d:\\CTSDatas\\Bay" (l 1).ToString() "\\" monthCalendar1.SelectionStart.Date.ToString("yyyy-MM"));
DirectoryInfo[] daydelcts = monthcts.GetDirectories();
foreach (DirectoryInfo info in daydelcts)
{
if (DateTime.TryParse(info.Name.Substring(0, 10), out date))
{
if (date.Date < monthCalendar1.SelectionStart.Date)
{
info.Delete(true);
}
}
}
}
//for (int j = 1; j < deletemonth; j ) //删除多余月份
//{
DirectoryInfo[] errormonth = folder.GetDirectories();
foreach (DirectoryInfo info in errormonth)
{
if (DateTime.TryParse(info.Name.Substring(0, 7), out date))
{
if (date.Month < monthCalendar1.SelectionStart.Month)
{
info.Delete(true);
}
}
}
DirectoryInfo monthdel = new DirectoryInfo(@"d:\logs\" monthCalendar1.SelectionStart.Date.ToString("yyyy-MM") "\\");
FileInfo[] daydell = monthdel.GetFiles("*.log.*");
foreach (FileInfo info in daydell)
{
if (DateTime.TryParse(info.Name.Substring(0, 10), out date))
{
if (date.Day < monthCalendar1.SelectionStart.Day)
{
info.Delete();
}
}
if (info.LastWriteTime < monthCalendar1.SelectionStart.Date)
{
info.Delete();
}
}
//DateTime delm = monthCalendar1.SelectionStart.AddMonths(j - deletemonth);
//DirectoryInfo monthdell = new DirectoryInfo(@"d:\logs\" delm.ToString("yyyy-MM"));
//if (monthdell.Exists)
//{
// monthdell.Delete(true);
//}
//}
}
}
}