Today's date instead of YYYYMMDD
-
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-YYYYMMDDI 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
-
-
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
-
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.
-
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()
-