Community
    • Login

    Systematic addition of text and the current file name into 320 files

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 3 Posters 565 Views 1 Watching
    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.
    • Aaron MillsA Offline
      Aaron Mills
      last edited by

      I’ve seen a topic covering how to insert the filename as text through some mouse clicks. I have some 320+ HTML files that are generated using DocFlex. Unfortunately, this tool does not generate a <title> element. I need to add one to 300 files. I would rather not do that through a mouse click. Any suggestions?

      1 Reply Last reply Reply Quote 0
      • Terry RT Offline
        Terry R
        last edited by

        @Aaron-Mills said in Systematic addition of text and the current file name into 320 files:

        how to insert the filename as text

        Perhaps read this thread which I was involved in some time ago. It could be a good starting point. You will likely need to alter some of the process to suit your needs, but at least it outlines the keystrokes (mouse) commands and it may help you solve the issue. By all means come back to this thread once you have read that with any questions.

        https://community.notepad-plus-plus.org/topic/17035/batch-function-need-to-add-filename-at-the-end-of-each-paragraph

        Terry

        1 Reply Last reply Reply Quote 1
        • mkupperM Offline
          mkupper
          last edited by

          @Aaron-Mills - I use Windows command prompt’s built in scripting and GNU sed to do what you need. For example, start up command prompt and cd to the top directory of where your HTML files are. Run this command for /r %i in (*.htm) do @echo %~ni You will see a list with the file names for each *.htm files from the current directory on down.

          Let’s say you want to add a <title>file-name</title> element at the top of the <head> section of each file.

          for /r %i in (*.htm) do sed -i -r -e "s~(<head>)~\1\n<title>%~ni</title>~" "%i"
          del sed??????
          

          You asked for the file name. If you also want the file extension included in the title then use %~nxi
          If you want or need to use the full file path then it gets painful. While the full path is available using %~fi you can’t use it as-is in a regular expression as the path contains \ backslash characters. There are workarounds but that’s getting out of the scope of how to do this given my suggestion does not use Notepad++.

          The second line with del sed?????? removes the temporary files created by sed’s -i command line option which I used to do in-place editing of all the HTML files.

          1 Reply Last reply Reply Quote 0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors