Thursday, June 3, 2010

Find Difference in Modified Dates in Files and Now



I recently wrote the program DOFF. It essentially finds the difference in x amount of days from a file modified and now.



       public void DirSearch(string sDir)
        {
            try
            {
                foreach (string d in Directory.GetDirectories(sDir))
                {
                    foreach (string f in Directory.GetFiles(d))
                    {
                        DateTime y;
                        double x;


                        y = GetXDays(
                            Convert.ToInt32(txtDaysOld.Value));
                        x = Convert.ToDouble(
                            (Directory.GetLastWriteTime(f)-y).
                            TotalDays.ToString());
                        
                        if (x < 0)
                        {
                            lstDeleteMe.Items.Add(f);
                        } 
                    }
                    DirSearch(d);
                }
            }
            catch (System.Exception excpt)
            {
                ntyDoff.ShowBalloonTip
               (
               5000,
               appTitle,
               excpt.Message,
               ToolTipIcon.Error);
            }




        }
        public DateTime GetXDays(int x)
        {
            return DateTime.Today.
                AddDays((Convert.ToInt32(
                x)) * -1);
        }


No comments:

Post a Comment

Generating "Always On Top" NSWindow in macOS across all detected displays

Also: Using UIKit & Cocoa Frameworks using Objective-C In m acOS or OS X , written in either Objective-C or Swift  Langues, you m...