Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# delete files older than 10 days

using System.IO; 

string[] files = Directory.GetFiles(dirName);

foreach (string file in files)
{
   FileInfo fi = new FileInfo(file);
   if (fi.LastAccessTime < DateTime.Now.AddDays(-10))
      fi.Delete();
}
Comment

c# delete files older than x months

using System.IO; 

string[] files = Directory.GetFiles(dirName);

foreach (string file in files)
{
   FileInfo fi = new FileInfo(file);
   if (fi.LastAccessTime < DateTime.Now.AddMonths(-3))
      fi.Delete();
}
Comment

c# delete files older than 10 days

using System.IO; 

string[] files = Directory.GetFiles(dirName);

foreach (string file in files)
{
   FileInfo fi = new FileInfo(file);
   if (fi.LastAccessTime < DateTime.Now.AddDays(-10))
      fi.Delete();
}
Comment

c# delete files older than x months

using System.IO; 

string[] files = Directory.GetFiles(dirName);

foreach (string file in files)
{
   FileInfo fi = new FileInfo(file);
   if (fi.LastAccessTime < DateTime.Now.AddMonths(-3))
      fi.Delete();
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: unity right click on gameobject 
Csharp :: how to check the tag of a collider in unity 
Csharp :: c# list to string comma separated 
Csharp :: check dotnet version command line 
Csharp :: open scene unity 
Csharp :: simple reset transform.rotation c# 
Csharp :: c# remove crlf from string 
Csharp :: C# open a new form 
Csharp :: wpf label text in center 
Csharp :: how to detect collision in unity 
Csharp :: unity mirror get ip address 
Csharp :: json ignore property c# 
Csharp :: get unix time in seconds C# 
Csharp :: c# generate random date 
Csharp :: stop audio unity 
Csharp :: dotnet get directory of executable 
Csharp :: asp.net core get request ip address 
Csharp :: find closest gameobject unity 
Csharp :: unity 2d detect click on sprite 
Csharp :: c# remove last value from list 
Csharp :: c# get script directory 
Csharp :: c# print out 
Csharp :: c# post get request 
Csharp :: unity movetowards 2d 
Csharp :: get values from range entity framework 
Csharp :: how to get executable path in wpf 
Csharp :: string to list c# 
Csharp :: currentTimeMillis c# 
Csharp :: c# date to string yyyy-mm-dd 
Csharp :: snx turn off linux 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =