Community
    • Login

    Preserve file modification date

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 4 Posters 2.6k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • bnoteB
      bnote
      last edited by

      Is there a way to preserve file’s modification time unchanged after save, as it was before editing?

      Thank you.
      .

      1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones
        last edited by

        Let me get this straight: you want to modify (change) the file, then save it, but not have the file’s modification time changed? It is the default behavior of Notepad++ to follow standard practices and update the modification time when a file is modified; otherwise, the modification time becomes meaningless.

        If you want to corrupt the modification time, on your own, after saving, you can use a program similar to the linux touch utility (like touch.exe, which can be found in the gnuwin32 port of coreutils for Windows). And there’s even a way (using a plugin like NppExec) to create a script that runs the NPP save, then immediately runs touch.exe or similar, and you could assign that script to a keystroke – even overriding the default Ctrl+S, if you wanted to.

        1 Reply Last reply Reply Quote 3
        • gstaviG
          gstavi
          last edited by

          Obviously NP++ does not modify timestamps directly.
          NP++ uses system API to open file for write and this call has a desirable side effect of updating modification time.
          Wanting to keep file’s modification time unchanged after its contents were changed is something that is typically reserved for malicious users.

          Scott SumnerS 1 Reply Last reply Reply Quote 3
          • Scott SumnerS
            Scott Sumner @gstavi
            last edited by

            The OP did not state WHY s/he wanted to retain the file’s old modification time. Let’s presume there is a perfectly valid reason for wanting this.

            I didn’t try it but it sure seems like something that could be scripted to run after a file-save event occurs. Probably wouldn’t want this for every file, but maybe a file with a specific name, or located in a specific folder…with script code all could likely be done…

            Of course, maybe changing the mod time in such a manner would cause N++'s File Status Auto-Detection logic to fire if that feature is enabled (suppose it could be disabled to prevent this potential issue).

            1 Reply Last reply Reply Quote 3
            • bnoteB
              bnote
              last edited by

              • ‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’’ @PeterJones

              Let me get this straight: you want to modify (change) the file, then save it, but not have the file’s modification time changed?

              Yeah.

              … to follow standard practices

              Whose standard practices and for whom?
              The essence of the question is exactly to move away from standard practice.

              … otherwise, the modification time becomes meaningless.

              Hm-m… Meaningless… For you? May be.
              But for me - just vice-versa.

              … you want to corrupt the modification time, …

              Do not say such things out loud.
              I want to keep it unchanged. You see the difference between this terms?

              … on your own, after saving, you can use …

              Thank you. Very much!
              I have a lot of I can and before, and after :)
              I have the bundle of such applications for Windows.
              And surrogate automation I have already now.
              However, I want not ‘after saving’, but instead of it, by the forces of Npp itself.

              • ‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’’ @gstavi

              Obviously … API …

              I think so too.
              However, nothing prevents to save opened file’s attributes in dark and cool place, and then bring them back. There are a lot of SetFileTime related functions.

              … that is typically reserved for malicious users.

              And you too - do not say such things out loud.

              • ‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’’ @Scott Sumner

              The OP did not state WHY s/he wanted to retain the file’s old modification time. Let’s presume there is a perfectly valid reason for wanting this.

              Thank you for moral support :)

              … would cause N++'s File Status Auto-Detection …
              May be. And Monitoring too.
              But it is a very special case and the interference of these functions should simply not be allowed at the level of the Npp itself. Especially because the timestamp changing event will raise twice - first by OS, and the second - by Npp, when time stam will restored.

              I have ownwrited application that run 24x5 and I use API Function ‘WriteFile’, constantly appending data w/o closing handle. I tried now on this remoted PC to open this log in old Npp 6.6.2 - Auto-Detection do not work. I try open it as share on my desktop Npp 7.3.2 - nor Auto-Detection, nor Monitoring not work. But the file is intensilty appending :) and OS show the unchanged time of file creating.

              ‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’’
              OK. At least - few words about wtf it need for me :)

              I often have to go to the archives of code, both my own and others. In Far-manager this is all quite easy and meticulously (time, content, size) is compared. Troubles appears when the difference between files is in extra space, linebreak etc. It need to correct 2-3 bytes of code, but, getting identical content, I loose historical timestamp, in first, and in second - got error of compare by time :)

              It is very troublesome to use a third party programs for this purpose - it nee to save original time by some manner, edit-save file and set saved time, that need to be passed by some manner too…

              If Npp had this feature, but I already guess that it does not have it, then it would be enough to spit out the file from the archive, edit it and throw it back.
              .

              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors