Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Random text in multiple files

    General Discussion
    2
    3
    302
    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 Gautier
      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 Kilborn 1 Reply Last reply Reply Quote 0
      • Alan Kilborn
        Alan Kilborn @Antoine Gautier last edited by

        @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', '\n', '\r'][editor.getEOLMode()]
            rawtext = str(editor.getText())
            rawtextlines = rawtext.splitlines()
            random.shuffle(rawtextlines)
            randomizedtext = EOLchar.join(rawtextlines)
            editor.setText(randomizedtext)
            editor.endUndoAction()
        
        Antoine Gautier 1 Reply Last reply Reply Quote 3
        • Antoine Gautier
          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
          • First post
            Last post
          Copyright © 2014 NodeBB Forums | Contributors