# Renaming <title> tags using HTML file names

• I would like to Batch Title hundreds of html files using there File Names with Spaces Added & the Extension removed.

AlmostPersuaded.html “File to be Titled”

I would like the Title tag to be, with Spaces in front of the Capitol letters & the Extension .html Removed:

Almost Persuaded “Title for tag”

Renaming utilities & all searches seem to do the reverse. Can this be done with Notepad++ or a plugin to it. I have done some simply amazing things with Notepad++ so I know it is capable!

Any help, thoughts or ideas appreciated. Thank You, Kevin

• I see some possible hope using NppExec plugin if anyone could show the how?

• The empty <title> </title> tag is in the html files already. So if the files name could have spaces before the Capitol letters & the extension .html removed. The part about Replacing “<title>” with “<title>Almost Persuaded” should be the easier part.

• You might be able to do it within Notepad++ using one of the scripting plugins (probably harder in NppExec, really), but since it wouldn’t likely be making use of the uniqueness, you could do it directly in your language of choice, without the Notepad++ overhead.

------

======

If you had gnu/linux like commands in your path (for example, GnuWin32 from http://gnuwin32.sourceforge.net/packages.html, or using git-bash, or windows 10 pro’s new linux subsystem), it could probably be done through the command line, using a for loop and an in-place sed command.

If you wanted a standalone programming language route (like Perl, Python, or Lua), here is an example Perl script I just whipped up in a few minutes, using strawberry perl. (I made it verbose, so that it was easily commented, so you could translate to another language of your choice, if you don’t have/want a perl interpreter):

#!perl
# assuming you saved this script as c:\path\to\script.pl
# assuming strawberry perl [https://strawberryperl.com/] (or similar) is in your path
# open cmd.exe in the directory with the files, and run
#       perl c:\path\to\script.pl
use autodie;    # open and similar commands will give meaningful errors automatically

foreach $f ( <*.html> ) { # loop through the filenames in the current directory my$ft = $f; # grab the name of the file$ft =~ s/.html//;                   #   remove the .html at the end
$ft =~ s/(?-i)\S\K([A-Z])/$1/g;    #   look for all capitals with a non-space character before it, and put a space before  -- this is using a regular expression syntax similar to Notepad++'s PCRE syntax
warn "ft => $ft\n"; open my$in_fh, '<', $f; # open the current file for input open my$out_fh, '>', "$f.tmp"; # open a .tmp for output local$/ = "<title>";                   # we'll tell perl to grab everything until the first <title> start...
my $str = <$in_fh>;                     # ... and grab it ...
print {$out_fh}$str;                   # ... and print it to the output
$/ = "</title>"; # now we want to grab until the end of this </title>$str = <$in_fh>; # grab until the end </title> print {$out_fh} "$ft</title>"; #$/ = "\n";                              # now grab normal lines...
print {$out_fh}$_ while $_ = <$in_fh>; # pipe through the rest of the file unchanged
close $out_fh; close$in_fh;
rename("$f.tmp",$f);                   # rename .tmp to the original name...
}

• Wow Thank You, I’ll give it a shot. I spent the whole day today trying to do a macro. It seems to work however each time Copy Current Filename to Clipboard is used it always seems to be from the time before. Even though that file was saved & moved to the next tab. I do not get that. :(

• @Kevin-Wood

using a macro together with the clipboard is only useful if you need the current string over and over again.
A macro doesn’t save the action “get clipbaord content”, it saves the real string which is in the clipboard at that time.
You can check this in the shortcuts.xml file.

Eko

• @Eko-palypse Thank You, after many hours of tryin’ that’s kind of what I was figuring. :)

• @PeterJones I can not Thank You enough! I started to refurbish a mainly East Coast, Nova Scotia Music website just for fun “No Profit”. This script was used in the Retro Lyrics section. You can check out the site here: RetroLyrics section http://www.rbops.com/RetroLyrics/SevenSpanishAngels.html)

Originally 20 years ago the Lyrics were RTF files with DOC extensions that even if you downloaded them, you could not open them. ha ha So you can imagine after some repair to these files I am impressed. I made most of the site mobile friendly & installed many MP3 players on the artists pages.

All pretty much retired players who had all pretty much played with groups you grew up listening to. Some good ole music.

Thank You Mr. PeterJones & I will definitely be learning some Perl from your example!