Generating the title's for alot of HTML pages

  • Tabble
  • Born
  • Born
  • Tabble
  • Posts: 4

Post 3+ Months Ago

I'm working with alot of files, and basically just need to know how to take the file name and add it to the title.

The files are like this for example: led_zeppelin-kashmir.html

and I would need it to automatically take the file name and add it to the title so the end result would look like this:

MySitesName.com - Led Zeppelin - Kashmir

Anyone know how to do this?

Another example just in case, would be like this...

Filename: rolling_stones-paint_it_black.html

End result for title of this html file: MySitesName.com - Rolling Stones - Paint it Black
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • this213
  • Guru
  • Guru
  • User avatar
  • Posts: 1260
  • Loc: ./

Post 3+ Months Ago

Providing your filenames are as shown, this should work for you:

Code: [ Select ]
opendir(THISDIR,"/directory/path/to/files");
while ($file = readdir(THISDIR) ){
    push @filenames, $file;
}
closedir(THISDIR);
chomp @filenames;
foreach $fn (@filenames) {
    if ($fn =~ /.+\.html/) {
        my($rawsong,$extention)=split(/\./,$fn);
        my($author,$title)=split(/\-/,$rawsong);
        $author =~ s/_/ /g;
        $title =~ s/_/ /g;
        print qq~Author: $author\nTitle: $title\nPage: $fn\n\n~;
        # You can do what you want with this information now, this is just to show that you do have it
    }
}
  1. opendir(THISDIR,"/directory/path/to/files");
  2. while ($file = readdir(THISDIR) ){
  3.     push @filenames, $file;
  4. }
  5. closedir(THISDIR);
  6. chomp @filenames;
  7. foreach $fn (@filenames) {
  8.     if ($fn =~ /.+\.html/) {
  9.         my($rawsong,$extention)=split(/\./,$fn);
  10.         my($author,$title)=split(/\-/,$rawsong);
  11.         $author =~ s/_/ /g;
  12.         $title =~ s/_/ /g;
  13.         print qq~Author: $author\nTitle: $title\nPage: $fn\n\n~;
  14.         # You can do what you want with this information now, this is just to show that you do have it
  15.     }
  16. }

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 88 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.