Community

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

    Add specific line to a large quantity of .nfo files

    Help wanted · · · – – – · · ·
    3
    4
    69
    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.
    • Eric St-Arnauld
      Eric St-Arnauld last edited by

      Hi, I have a collection of over 1000 .nfo files in which I would like to add this specific line in the beginning of each files:

      <?xml version=“1.0” encoding=“UTF-8” standalone=“yes”?>

      Is the way that I can do this?

      Thanks for any cue!

      PeterJones 1 Reply Last reply Reply Quote 0
      • PeterJones
        PeterJones @Eric St-Arnauld last edited by PeterJones

        @Eric-St-Arnauld

        Search > Find in Files.

        • FIND = \A^
        • REPLACE = <?xml version="1.0" encoding="UTF-8" standalone="yes"?>\r\n
        • FILTERS = *.nfo
        • Directory = (set as appropriate)
        • SEARCH MODE = Regular Expression.

        Matching only at the beginning of a file isn’t always easy, especially in Find In Files. Based on previous discussions, including https://community.notepad-plus-plus.org/topic/19748/how-to-insert-text-into-the-second-line-with-regex-in-notepad/14 and https://community.notepad-plus-plus.org/topic/15998/regex-anchor-for-beginning-of-file, I believe that to anchor your search at the beginning, \A^ should work. If it doesn’t, restore you data from backups, and give us more information, so we can help figure out what went wrong.

        (it’s also often a good idea to test on just one file first – change filter to blah.nfo, where that’s just one file’s name – it’s easier to undo the action that way.)

        caveat emptor

        This regex makes sense to me, based on my understanding of your issue, and is published here to help you learn how to do this. I make no guarantees or warranties as to the functionality for you. You are responsible to save and backup all data before and after running this regex.

        Alan Kilborn 1 Reply Last reply Reply Quote 1
        • Eric St-Arnauld
          Eric St-Arnauld last edited by

          @PeterJones:
          That did the trick! Thanks a lot!

          1 Reply Last reply Reply Quote 1
          • Alan Kilborn
            Alan Kilborn @PeterJones last edited by

            @PeterJones said in Add specific line to a large quantity of .nfo files:

            Matching only at the beginning of a file isn’t always easy…

            But, isn’t it easy now? (Now meaning 7.9.1 and later)
            At that point, N++ regex got a fix for \A which allows that sort of replacement to work, without a ^ hanging off the end, or other tricks.

            From the 7.9.1 announcement is item number 3:

            3. Fix RegEx look behind operations and \A and and \b and \z (Fix #713, #1870, #2216, #2360, #9004, #4855).

            Of course, OP in this thread could be using some earlier version…

            1 Reply Last reply Reply Quote 2
            • First post
              Last post
            Copyright © 2014 NodeBB Forums | Contributors