Hi I am new to c# and trying to learn. I have written this code to delete files from a folder older then 30 days. I think there is something seriously wrong with my logic. It deletes any new files as well. Thanks for any help
Code:static void Main(string[] args) { DateTime timenow = System.DateTime.Now; DateTime timeminus = timenow.AddDays(-30); string[] files = Directory.GetFiles(@"c:\temp\"); DateTime time = Directory.GetCreationTime(@"c:\temp\"); foreach (string file in files) if (time < timeminus) File.Delete(file); else break; }



LinkBack URL
About LinkBacks


