Notepad++ python , remove the path from the text file



  • script

    Filename = notepad.getCurrentFilename()
    editor.addText( Filename )
    

    Result - “d:\folder\file.txt”

    What I want - “file.txt”



  • @Valdisnei-Souza

    Well, you have to use Python code to do that.
    The “editor” functions give you all of the information; if you want a subset, you have to do it yourself.

    You might try:

    import os
    Filename2 = Filename.rsplit(os.sep, 1)[-1]
    


  • Perfect, it works. This is to replace strings in my sourcepawn template.

    import time
    import os
    
    Filename = notepad.getCurrentFilename()
    FilenameEnd = Filename.rsplit(os.sep, 1)[-1]
    timeStr = time.strftime( '%I:%M %p' + ' - ' + '%d-%m-%Y' )
    
    editor.rereplace(r"TM_FILEDATE", ( timeStr ))
    editor.rereplace(r"TM_FILENAME", ( FilenameEnd ))
    

    Thanks!!


Log in to reply