hello folks., how to delete files which are more than one month old using c# script. i am using framework 2.0..
+2
A:
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.
SLaks
2010-07-27 13:28:44
+5
A:
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();
}
Anthony Pegram
2010-07-27 13:28:59
Nice format-fix on line #1
sshow
2010-07-27 13:40:35
@Joel, that's simply genius. Thanks.
Anthony Pegram
2010-07-27 13:58:49