Community
    • Login

    Random text in multiple files

    Scheduled Pinned Locked Moved General Discussion
    4 Posts 2 Posters 2.1k 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
      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
        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
          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
            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
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors