using System;
using System.IO;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
string folderPath = Path.Combine(Directory.GetCurrentDirectory(), "targetFolder");
string[] files = Directory.GetFiles(folderPath);
DateTime now = DateTime.Now.AddDays(-3); //3일 전 파일까지 검출용.
foreach (string file in files)
{
FileInfo fileInfo = new FileInfo(file);
//A < B = 1, A == B = 0, A > B = -1
if (DateTime.Compare(now, fileInfo.LastWriteTime) > 0) //기준보다 오래된 파일 삭제
{
fileInfo.Delete();
}
}
}
}
}'C# > Console' 카테고리의 다른 글
| [C#] Stopwatch 경과 시간 확인하기 (tick, milliseconds, timespan) (0) | 2025.09.29 |
|---|---|
| [C#] 구조체와 클래스 차이. 값 복사와 참조 형식 (0) | 2025.09.29 |
| [C#] Xml 읽어오기 (System.Xml) (0) | 2025.05.23 |
| [C# Console] Base64 직접 만들어보기 (Convert.ToBase64String, Convert.FromBase64String) (0) | 2025.04.11 |
| [C# Console] AES256 사용 (+ 자바) (0) | 2025.04.02 |