Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

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

    Help wanted · · · – – – · · ·
    2
    3
    69
    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.
    • Valdisnei Souza
      Valdisnei Souza last edited by

      script

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

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

      What I want - “file.txt”

      Alan Kilborn 1 Reply Last reply Reply Quote 0
      • Alan Kilborn
        Alan Kilborn @Valdisnei Souza last edited by

        @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]
        
        1 Reply Last reply Reply Quote 2
        • Valdisnei Souza
          Valdisnei Souza last edited by

          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!!

          1 Reply Last reply Reply Quote 1
          • First post
            Last post
          Copyright © 2014 NodeBB Forums | Contributors