• Login
Community
  • Login

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

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
3 Posts 3 Posters 297 Views
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.
  • A
    Aaron Mills
    last edited by Jan 11, 2021, 10:28 PM

    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
    • T
      Terry R
      last edited by Jan 11, 2021, 10:32 PM

      @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
      • M
        mkupper
        last edited by Jan 13, 2021, 9:10 PM

        @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
        2 out of 3
        • First post
          2/3
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors