1

我想删除 3 个月前创建的文件夹及其内容............我写了一个代码......但是在给定条件时不起作用

protected void Button1_Click(object sender, EventArgs e)
    {
        string NewDirectory = "C:\\New Foouterlder\\delete";


        DeleteDirectoryIfExist(NewDirectory);


    }
    private void DeleteDirectoryIfExist(string NewDirectory)
    {
        DirectoryInfo di = new DirectoryInfo("C:\\New Foouterlder\\delete");

        try
        {
            if (System.IO.Directory.Exists(NewDirectory))
                {
                    if (di.CreationTime< DateTime.Now.AddMonths(-3))
                    {

                        Response.Write(MydateTime);
                        Directory.Delete(NewDirectory, true);
                   }
           else

                    {
                       Label1.Text = "Directory Not Exist";

                   }
            }
            Response.Write(di.CreationTime);



        }
        catch (IOException _err)
        {
            Response.Write(_err.Message);
        }
    }
}
}

di.CreationTime 为 1/1/1601 5:30:00 AM ....为什么

4

0 回答 0