• Login
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.
  • A
    Antoine Gautier
    last edited by Jan 22, 2020, 10:20 AM

    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.

    A 1 Reply Last reply Jan 22, 2020, 12:47 PM Reply Quote 0
    • A
      Alan Kilborn @Antoine Gautier
      last edited by PeterJones Jan 14, 2024, 6:37 PM Jan 22, 2020, 12:47 PM

      @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.

      A 1 Reply Last reply Jan 22, 2020, 1:10 PM Reply Quote 3
      • A
        Antoine Gautier @Alan Kilborn
        last edited by Jan 22, 2020, 1:10 PM

        @Alan-Kilborn

        The script is 100% functional

        Thank you so much, dear Alan :)

        1 Reply Last reply Reply Quote 2
        • A
          Alan Kilborn
          last edited by Jan 14, 2024, 8:56 PM

          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