Notepad++ new file names

5,078

Solution 1

I just did this using the Python Script plugin for NPP...

notepad.clearCallbacks([NOTIFICATION.BUFFERACTIVATED])
def my_callback(args):
    if notepad.getBufferFilename(args["bufferID"]) == "new  1":
        fmt = '%Y%m%d%H%M%S'
        d = datetime.datetime.now()
        d_string = d.strftime(fmt)
        notepad.saveAs('X:\\Documents\\Notepad++_autosave\\%s.txt' % d_string)
notepad.callback(my_callback, [NOTIFICATION.BUFFERACTIVATED])

With the above code, as soon as I type Ctrl+N, the new file is created and saved instantly with the name formatted as defined in 'fmt' above. The path for the file to be saved is defined above as well; change it to suit your environment.

Solution 2

Notepad ++ has a plugin Autosave2 that saves your documents with a time stamp in the file name like this :

ToDo.txt.2013-04-19 10.13.09

ToDo.txt.2013-04-19 10.14.09

ToDo.txt.2013-04-19 10.15.09

Share:
5,078

Related videos on Youtube

vt.
Author by

vt.

Updated on September 18, 2022

Comments

  • vt.
    vt. over 1 year

    Is there a way to have Notepad++ generate new file names with the current date?

    Like this: YYYY_MM_DD_new1.txt or similar. Currently it just names them: new1, new2, etc.

    Date in the file name will work great with autosave, there will be no name conflicts after NPP restart.

    All I want is a way to store sessions between restarts. I want to autosave even the unnamed files.

    Thanks.

    • Joshua Nurczyk
      Joshua Nurczyk almost 11 years
      Is this for use with the AutoSave plugin or something similar?
    • Raystafarian
      Raystafarian almost 11 years
      sublimetext saves sessions
    • vt.
      vt. almost 11 years
      Yes, for use with autosave. I am not interested in sublimetext, thanks. Notepad++ saves sessions too, just doesn't assign unique filenames.
  • Shekhar
    Shekhar almost 11 years
    aah, my bad. But your requirements seem to specific, I guess you will have to get someone to make a plugin that does it for you.
  • vt.
    vt. almost 11 years
    I created it. Didn't even think of that originally.
  • Shekhar
    Shekhar almost 11 years
    hey great job, I think you should publish a link to your plugin here and mark it as the asnwer
  • mwoliver
    mwoliver almost 9 years
    As of v6.7.9.2 of NPP, the single-quote for 'new 1' in the 'if' test fails, but replacing the single-quote with double-quote restored functionality.
  • vt.
    vt. about 7 years
    Great. I modified condition to: notepad.getBufferFilename(args["bufferID"])[0:4] == 'new ': and filename: newFilename = ('%s\\%s.txt' % (os.environ['TEMP'], d_string)) Also put this to startup.py