Create REN Batch File?



  • How can I automatically convert a list of filenames (in a text file) to reverse the filename based on a dash?

    My file has (hundreds) of filenames listed … (I can easily remove the .epub extension before conversion, and add it back after the list is “fixed”.)

    This would be the starting file contents …

    Pride and Prejudice - Jane Austen
    Moby Dick - Herman Melville
    A Tale of Two Cities - Charles Dickens
    

    This would be the converted file contents …

    REN "Pride and Prejudice - Jane Austen" "Jane Austen - Pride and Prejudice"
    REN "Moby Dick - Herman Melville" "Herman Melville - Moby Dick"
    REN "A Tale of Two Cities - Charles Dickens" "Charles Dickens - A Tale of Two Cities"
    


  • @Ron-Ball said in Create REN Batch File?:

    Pride and Prejudice - Jane Austen
    Moby Dick - Herman Melville
    A Tale of Two Cities - Charles Dickens

    From the given example you would build three groups like
    find:(.+)( - )(.+)
    and
    replace: REN "$1$2$3" "$3$2$1"

    Hopefully your data is exactly as posted.



  • Hello, @ron-ball and All,

    Really easy with regular expressions !

    So , assuming a simple list of filenames, with any extension, like below :

    Pride and Prejudice - Jane Austen.epub
    Moby Dick - Herman Melville.epub
    A Tale of Two Cities - Charles Dickens.epub
    
    • Open the Replace dialog ( Ctrl + H )

    • SEARCH (?-s)^(.+)(\x20-\x20)(.+)(\..+)

    • REPLACE ren "$0" "\3\2\1\4"

    • Tick the Wrap around option

    • Select the Regular expression search mode

    • Click, once, on the Replace all button

    You should get the expected result :

    ren "Pride and Prejudice - Jane Austen.epub" "Jane Austen - Pride and Prejudice.epub"
    ren "Moby Dick - Herman Melville.epub" "Herman Melville - Moby Dick.epub"
    ren "A Tale of Two Cities - Charles Dickens.epub" "Charles Dickens - A Tale of Two Cities.epub"
    

    Voila ;-))

    Best Regards,

    guy038



  • @guy038 This is awesome! Thank you so much! It worked perfectly.