Community
    • Login

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

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 2 Posters 551 Views 1 Watching
    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 Offline
      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 Offline
        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 Offline
          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

          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
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors