Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display file's modification date in Notepad++

Is it possible to display the date and time of the last modification on the currently opened file in Notepad++? It would be nice to have that information always visible, e.g. in the status bar.

I am using Notepad++ v5.9.3 (UNICODE) on Windows XP SP3.

like image 992
baruch Avatar asked Jul 11 '26 08:07

baruch


1 Answers

C# Console app; I wrote this up in five minutes because it's all I have and would like this. It's not pretty but as good as I can do for now. It's a starting point at least.

Notepad++ Last Date Modified

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Notepadd___DateModified
{
    class Program
    {
        [DllImport("user32.dll", SetLastError = true)]
        static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

         [DllImport("user32.dll", EntryPoint = "SendMessage", CharSet = System.Runtime.InteropServices.CharSet.Auto)] 
        public static extern bool SendMessage(IntPtr hWnd, uint Msg, int wParam, StringBuilder lParam);

        [DllImport("user32.dll", SetLastError = true)]
        public static extern IntPtr SendMessage(int hWnd, int Msg, int wparam, int lparam);

        [DllImport("user32.dll")]
        public static extern int SendMessage(IntPtr hWnd, int msg, int Param, string s);

        const int WM_GETTEXT = 0x000D;
        const int WM_SETTEXT = 0x000c;
        const int WM_GETTEXTLENGTH = 0x000E;

        static void Main(string[] args)
        {
            while (true)
            {

                foreach (Process p in Process.GetProcessesByName("Notepad++"))
                {
                    if (p.Id != Process.GetCurrentProcess().Id)
                    {
                        try
                        {
                            DateTime LastModified = Directory.GetLastWriteTime(p.MainWindowTitle.Replace(" - Notepad++", ""));

                            IntPtr childHandle;
                            childHandle = FindWindowEx(p.MainWindowHandle, IntPtr.Zero,  "msctls_statusbar32", null);

                            StringBuilder subtitle = new StringBuilder();
                            Int32 subsize = SendMessage((int)childHandle, WM_GETTEXTLENGTH, 0, 0).ToInt32();

                            if (subsize > 0)
                            {
                                subtitle = new StringBuilder(subsize + 1);
                                SendMessage(childHandle, (int)WM_GETTEXT, subtitle.Capacity, subtitle);
                            }

                            if (!subtitle.ToString().Contains(" - Last Modified: " + LastModified.ToString()))
                            {
                                SendMessage(childHandle, WM_SETTEXT, 0, subtitle.ToString().Split(new string[] { " - Last Modified: " },StringSplitOptions.None)[0] + " - Last Modified: " + LastModified.ToString());
                                Console.Out.WriteLine(subtitle + " - Last Modified: " + LastModified.ToString());
                            }
                        }
                        catch
                        {
                            break;
                        }
                    }
                    else return;
                }
                Thread.Sleep(1000);
            }
        }
    }
}
like image 165
DeusAphor Avatar answered Jul 14 '26 16:07

DeusAphor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!