Random text in multiple files



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



  • @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()
    


  • @Alan-Kilborn

    The script is 100% functional

    Thank you so much, dear Alan :)


Log in to reply