Community
    • Login

    Random text in multiple files

    Scheduled Pinned Locked Moved General Discussion
    4 Posts 2 Posters 2.9k 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.
    • Antoine GautierA Offline
      Antoine Gautier
      last edited by

      Hello,

      I have several lists of names (+100 lists) and I want to make them in random order :

      1. Raphaël NAME
      2. PATRICK NAME
      3. Louis NAME
      4. Emma NAME
      5. Gabriel NAME

      by

      1. Raphaël NAME
      2. PATRICK NAME
      3. Louis NAME
      4. Emma NAME
      5. Gabriel NAME

      I found this script “npp-randomizelines” on: https://github.com/ethanpil/npp-randomizelines

      The execution of this script applies only in the first tab, the rest of the tabs don’t make any changes.

      Can someone help me?

      Thank you.

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA Offline
        Alan Kilborn @Antoine Gautier
        last edited by PeterJones

        @Antoine-Gautier

        Here’s a changed version of that script that works on ALL files open in the primary view of Notepad++ – make sure you have open ONLY the files you want randomized before running!

        # -*- coding: utf-8 -*-
        
        from Npp import editor, notepad
        import random
        
        for (filename, bufferID, index, view) in notepad.getFiles():
            editor.beginUndoAction()
            notepad.activateFile(filename)
            EOLchar = ['\r\n', '\r', '\n'][editor.getEOLMode()]
            rawtext = str(editor.getText())
            rawtextlines = rawtext.splitlines()
            random.shuffle(rawtextlines)
            randomizedtext = EOLchar.join(rawtextlines)
            editor.setText(randomizedtext)
            editor.endUndoAction()
        

        --
        Moderator EDIT (2024-Jan-14): The author of the script has found a fairly serious bug with the code published here for those that use Mac-style or Linux-style line-endings in their files. The logic for Mac and Linux was reversed, and thus if the script was used on one type of file, the line-endings for the opposite type of file could end up in the file after the script is run. This is insidious, because unless one works with visible line-endings turned on, this is likely not noticed. Some detail on the problem is HERE. The script above has been corrected per that instruction.

        Antoine GautierA 1 Reply Last reply Reply Quote 3
        • Antoine GautierA Offline
          Antoine Gautier @Alan Kilborn
          last edited by

          @Alan-Kilborn

          The script is 100% functional

          Thank you so much, dear Alan :)

          1 Reply Last reply Reply Quote 2
          • Alan KilbornA Offline
            Alan Kilborn
            last edited by

            If you’ve used a script in this thread, you might want to double check your copy of it for a bug I’ve discovered.
            Look to previous postings in this topic thread where the script has been changed – find the text moderator edit (2024-Jan-14).
            There’s a link there that describes the bug in more detail, and shows what needs to be changed in an old copy (or you can simply grab a copy of the current version).

            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