Hi there,
I have a FolderWatcher.c s class that will monitor a given folder and delete files older than X number of days. I have the following methods. I need to add/show delete mothod using date time object.
i want to know couple of other stuff as well..returning an array list instead of string[] is better or not? What is the difference between timespan object and DateTime object?..Are there any benefits of using timespan object instead of datetime object?
Thanks in advance for the help!!
I have a FolderWatcher.c s class that will monitor a given folder and delete files older than X number of days. I have the following methods. I need to add/show delete mothod using date time object.
Code:
public static DateTime GetRelativeDateTime(int days, int hours, int minutes) { return DateTime.Now.AddDays(-days).AddHours(-hours).AddMinutes(-minutes); } public static string[] FilesOlderThan(DateTime dt) { DirectoryInfo directory = new DirectoryInfo(Directory.GetCurrentDirectory()); FileInfo[] files = directory.GetFiles(); //get FileInfos for the files in the current directory ArrayList older = new ArrayList(); //list to hold the result foreach (FileInfo file in files) { if (file.CreationTime < dt) //if smaller (older) than the relative time older.Add(file.Name); //add it to the list } }
Thanks in advance for the help!!
Comment