문제

how to delete files which are more than one month old using c# script. i am using framework 2.0..

도움이 되었습니까?

해결책

string path = @"C:\Temp\"; //"

DirectoryInfo dirInfo = new DirectoryInfo(path);
FileInfo[] fileInfos = dirInfo.GetFiles();

foreach (FileInfo fileInfo in fileInfos)
{
    if (fileInfo.LastWriteTime < DateTime.Now.AddMonths(-1))
        fileInfo.Delete();
}

다른 팁

You can call Directory.GetFiles to find all files in a folder.
You can call File.GetLastWriteTime to check when the file was modified.
You can call File.Delete to delete a file.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top