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
YYYYMMDDwith 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() -
A Alan Kilborn referenced this topic on
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login