Community
    • Login

    Today's date instead of YYYYMMDD

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 2 Posters 517 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.
    • Yves DavignonY
      Yves Davignon
      last edited by

      Good day,

      I have a notepad++ file that I copy and paste from on a daily basis.

      I have this line:
      COPY TO .\lcpout\Removed-Mar2023\REMOVED-YYYYMMDD

      I manually replace the YYYYMMDD with today’s date but is there a way to have the YYYYMMDD reflect today’s date instead of the place holder?

      Tx for your help,

      Yves

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @Yves Davignon
        last edited by

        @Yves-Davignon

        e1721c30-b389-4c1f-bbdc-22f681d4d888-image.png

        1 Reply Last reply Reply Quote 1
        • Yves DavignonY
          Yves Davignon
          last edited by

          Tx Alan,

          That will indeed insert today’s date where the cursor is located.

          What I am/was looking for is a Date variable that I could insert in my file and when the notpad++ file is open, that date is populated with today’s date. If it can be done of course.

          Yves

          Alan KilbornA 1 Reply Last reply Reply Quote 0
          • Alan KilbornA
            Alan Kilborn @Yves Davignon
            last edited by

            @Yves-Davignon

            Ah. So you mean that at the time of file opening, you want to do a replace on YYYYMMDD with the current date. Gotcha.

            That would be fairly easy to script if you are willing to use a scripting plugin? More detail on what would be required for that is HERE.

            1 Reply Last reply Reply Quote 1
            • Alan KilbornA
              Alan Kilborn
              last edited by

              Anyway, here’s a demo script that could accomplish the goal. I call it ReplaceYyyymmddOnFileOpen.py:

              # -*- coding: utf-8 -*-
              
              # references:
              #  https://community.notepad-plus-plus.org/topic/24257
              
              #-------------------------------------------------------------------------------
              
              from Npp import *
              import time
              
              #-------------------------------------------------------------------------------
              
              class RYOFO(object):
              
                  def __init__(self):
                      notepad.callback(self.fileopened_callback, [NOTIFICATION.FILEOPENED])
                      notepad.callback(self.bufferactivated_callback, [NOTIFICATION.BUFFERACTIVATED])
                      self.process_next_buf_act = False
              
                  def fileopened_callback(self, args):
                      self.process_next_buf_act = True
              
                  def bufferactivated_callback(self, args):
                      if self.process_next_buf_act:
                          editor.replace('YYYYMMDD', time.strftime('%Y%m%d', time.localtime()))
                          self.process_next_buf_act = False
              
              #-------------------------------------------------------------------------------
              
              try:
                  ryofo
              except NameError:
                  ryofo = RYOFO()
              
              1 Reply Last reply Reply Quote 5
              • Alan KilbornA Alan Kilborn referenced this topic on
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors