Community
    • Login

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

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 2 Posters 276 Views
    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 SouzaV
      Valdisnei Souza
      last edited by

      script

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

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

      What I want - “file.txt”

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        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 SouzaV
          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
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors