Generating links from "filename.htm" plain text?

Discussion in 'HTML' started by Phillip Roncoroni, Jan 8, 2004.

  1. I'll hopefully be putting an archive of about 5,000 old html pages I've
    collected over the years on my website, for people to search thru, and
    Google to index.

    I generated a directory listing with:
    copy *.htm c:\archive >>c:\log.txt

    Now I have a log of:
    pg1.htm
    pg2.htm
    pg3.htm

    etc. but with their real filenames, and 5,000+ of them, in plain text, one
    per line.

    Is there a way to turn each of these filenames into a clickable link without
    having to do it manually?

    Thanks in advance.

    --

    goodcow
    goodcowfilms.com
    Phillip Roncoroni, Jan 8, 2004
    #1
    1. Advertising

  2. Phillip Roncoroni wrote:
    > Now I have a log of:
    > pg1.htm
    > pg2.htm
    > pg3.htm
    >
    > etc. but with their real filenames, and 5,000+ of them, in plain text, one
    > per line.
    >
    > Is there a way to turn each of these filenames into a clickable link without
    > having to do it manually?


    Perl.

    use strict;
    use warnings;
    open(FILE_LOG, "c:\\log.txt");
    print "<ul>\n";
    while (my $file = <FILE_LOG) {
    print "<li><a href=\"$file\">$file</a></li>\n";
    }
    print "</ul>\n";
    Leif K-Brooks, Jan 8, 2004
    #2
    1. Advertising

  3. "Leif K-Brooks" <> wrote in message
    news:vQ1Lb.151$...
    > Phillip Roncoroni wrote:
    > > Now I have a log of:
    > > pg1.htm
    > > pg2.htm
    > > pg3.htm
    > >
    > > etc. but with their real filenames, and 5,000+ of them, in plain text,

    one
    > > per line.
    > >
    > > Is there a way to turn each of these filenames into a clickable link

    without
    > > having to do it manually?

    >
    > Perl.
    >
    > use strict;
    > use warnings;
    > open(FILE_LOG, "c:\\log.txt");
    > print "<ul>\n";
    > while (my $file = <FILE_LOG) {
    > print "<li><a href=\"$file\">$file</a></li>\n";
    > }
    > print "</ul>\n";
    >


    Now how exactly do I run this, as I have no idea how to use Perl...

    --

    goodcow
    goodcowfilms.com
    Phillip Roncoroni, Jan 8, 2004
    #3
  4. Phillip Roncoroni

    Hunter Guest

    "Phillip Roncoroni" <> wrote in message
    news:iZ1Lb.34301$...
    > "Leif K-Brooks" <> wrote in message
    > news:vQ1Lb.151$...
    > > Phillip Roncoroni wrote:
    > > > Now I have a log of:
    > > > pg1.htm
    > > > pg2.htm
    > > > pg3.htm
    > > >
    > > > etc. but with their real filenames, and 5,000+ of them, in plain text,

    > one
    > > > per line.
    > > >
    > > > Is there a way to turn each of these filenames into a clickable link

    > without
    > > > having to do it manually?

    > >
    > > Perl.
    > >
    > > use strict;
    > > use warnings;
    > > open(FILE_LOG, "c:\\log.txt");
    > > print "<ul>\n";
    > > while (my $file = <FILE_LOG) {
    > > print "<li><a href=\"$file\">$file</a></li>\n";
    > > }
    > > print "</ul>\n";
    > >

    >
    > Now how exactly do I run this, as I have no idea how to use Perl...
    >


    Hi Philip -

    If you have telnet or ssh access to your server then ftp your file to the
    server.
    Then use an editor like vi to populate the file. Here are your steps:

    ftp file to server
    telnet to server and go to the path where you uploaded the file
    vi addlinks.pl
    be sure to add your perl path - *usually* #!/usr/bin/perl (if it's not there
    just type 'which perl')
    copy the script above into addlinks.pl removing the c:\\
    chmod 755 addlinks.pl
    then from the command line type: ./addlinks.pl log.txt

    hth, david


    --------------------------------------------------
    Exceptional Gift Baskets Online!
    http://cranberrycorners.ca/home.shtml
    Hunter, Jan 8, 2004
    #4
  5. Phillip Roncoroni

    Hunter Guest

    "Hunter" <> wrote in message
    news:Xz3Lb.27394$...
    >
    > "Phillip Roncoroni" <> wrote in message
    > news:iZ1Lb.34301$...
    > > "Leif K-Brooks" <> wrote in message
    > > news:vQ1Lb.151$...
    > > > Phillip Roncoroni wrote:
    > > > > Now I have a log of:
    > > > > pg1.htm
    > > > > pg2.htm
    > > > > pg3.htm
    > > > >
    > > > > etc. but with their real filenames, and 5,000+ of them, in plain

    text,
    > > one
    > > > > per line.
    > > > >
    > > > > Is there a way to turn each of these filenames into a clickable link

    > > without
    > > > > having to do it manually?
    > > >
    > > > Perl.
    > > >
    > > > use strict;
    > > > use warnings;
    > > > open(FILE_LOG, "c:\\log.txt");
    > > > print "<ul>\n";
    > > > while (my $file = <FILE_LOG) {
    > > > print "<li><a href=\"$file\">$file</a></li>\n";
    > > > }
    > > > print "</ul>\n";
    > > >

    > >
    > > Now how exactly do I run this, as I have no idea how to use Perl...
    > >

    >
    > Hi Philip -
    >
    > If you have telnet or ssh access to your server then ftp your file to the
    > server.
    > Then use an editor like vi to populate the file. Here are your steps:
    >
    > ftp file to server
    > telnet to server and go to the path where you uploaded the file
    > vi addlinks.pl
    > be sure to add your perl path - *usually* #!/usr/bin/perl (if it's not

    there
    > just type 'which perl')
    > copy the script above into addlinks.pl removing the c:\\
    > chmod 755 addlinks.pl
    > then from the command line type: ./addlinks.pl log.txt
    >


    Hi Philip - I made an error on the last step. It should just be
    ../addlinks.pl (without the filename)

    If you need a hand you can mail me at
    Hunter, Jan 8, 2004
    #5
  6. Phillip Roncoroni wrote:
    > I'll hopefully be putting an archive of about 5,000 old html pages
    > I've collected over the years on my website, for people to search
    > thru, and Google to index.
    >
    > I generated a directory listing with:
    > copy *.htm c:\archive >>c:\log.txt
    >
    > Now I have a log of:
    > pg1.htm
    > pg2.htm
    > pg3.htm
    >
    > etc. but with their real filenames, and 5,000+ of them, in plain
    > text, one per line.
    >
    > Is there a way to turn each of these filenames into a clickable link
    > without having to do it manually?
    >
    > Thanks in advance.


    put all your files in one folder, then run this at your command line.....

    <commandline>
    FOR /F "usebackq delims==" %i IN (`dir /b`) DO @echo "<a href=%i>%i</a><br>"
    >> allfiles.html

    </commandline>

    you will now have a file called allfiles.html
    Disco Octopus, Jan 8, 2004
    #6
  7. Phillip Roncoroni

    Jan Faerber Guest


    > Is there a way to turn each of these filenames into a clickable link
    > without
    > having to do it manually?





    Maybe you can use a simple search & replace tool.


    Jan
    Jan Faerber, Jan 8, 2004
    #7
  8. Leif K-Brooks wrote:

    > while (my $file = <FILE_LOG) {
    > print "<li><a href=\"$file\">$file</a></li>\n";
    > }


    <FILE_LOG should have a closing >.

    You should probably make use of chomp too.

    use strict;
    use warnings;
    open(FILE_LOG, "c:\\log.txt");
    print "<ul>\n";
    while (my $file = <FILE_LOG>) {
    chomp $file;
    print "<li><a href=\"$file\">$file</a></li>\n";
    }
    print "</ul>\n";

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me - http://www.goddamn.co.uk/tobyink/?page=132
    Toby A Inkster, Jan 8, 2004
    #8
  9. Toby A Inkster wrote:
    > <FILE_LOG should have a closing >.
    >
    > You should probably make use of chomp too.


    Yup, you're right. The first one is a typo, and the second was caused by
    me not using Perl enough to remember things like that.
    Leif K-Brooks, Jan 8, 2004
    #9
  10. "Hunter" <> wrote in message
    news:y64Lb.27926$...
    >
    > "Hunter" <> wrote in message
    > news:Xz3Lb.27394$...
    > >
    > > "Phillip Roncoroni" <> wrote in message
    > > news:iZ1Lb.34301$...
    > > > "Leif K-Brooks" <> wrote in message
    > > > news:vQ1Lb.151$...
    > > > > Phillip Roncoroni wrote:
    > > > > > Now I have a log of:
    > > > > > pg1.htm
    > > > > > pg2.htm
    > > > > > pg3.htm
    > > > > >
    > > > > > etc. but with their real filenames, and 5,000+ of them, in plain

    > text,
    > > > one
    > > > > > per line.
    > > > > >
    > > > > > Is there a way to turn each of these filenames into a clickable

    link
    > > > without
    > > > > > having to do it manually?
    > > > >
    > > > > Perl.
    > > > >
    > > > > use strict;
    > > > > use warnings;
    > > > > open(FILE_LOG, "c:\\log.txt");
    > > > > print "<ul>\n";
    > > > > while (my $file = <FILE_LOG) {
    > > > > print "<li><a href=\"$file\">$file</a></li>\n";
    > > > > }
    > > > > print "</ul>\n";
    > > > >
    > > >
    > > > Now how exactly do I run this, as I have no idea how to use Perl...
    > > >

    > >
    > > Hi Philip -
    > >
    > > If you have telnet or ssh access to your server then ftp your file to

    the
    > > server.
    > > Then use an editor like vi to populate the file. Here are your steps:
    > >
    > > ftp file to server
    > > telnet to server and go to the path where you uploaded the file
    > > vi addlinks.pl
    > > be sure to add your perl path - *usually* #!/usr/bin/perl (if it's not

    > there
    > > just type 'which perl')
    > > copy the script above into addlinks.pl removing the c:\\
    > > chmod 755 addlinks.pl
    > > then from the command line type: ./addlinks.pl log.txt
    > >

    >
    > Hi Philip - I made an error on the last step. It should just be
    > ./addlinks.pl (without the filename)
    >
    > If you need a hand you can mail me at
    >
    >


    Thanks, but I managed to get somebody else with a Unix box to just run the
    script for me with the file listing in question.

    --

    goodcow
    goodcowfilms.com
    Phillip Roncoroni, Jan 8, 2004
    #10
  11. "Disco Octopus" <> wrote in message
    news:_a4Lb.1791$...
    > Phillip Roncoroni wrote:
    > > I'll hopefully be putting an archive of about 5,000 old html pages
    > > I've collected over the years on my website, for people to search
    > > thru, and Google to index.
    > >
    > > I generated a directory listing with:
    > > copy *.htm c:\archive >>c:\log.txt
    > >
    > > Now I have a log of:
    > > pg1.htm
    > > pg2.htm
    > > pg3.htm
    > >
    > > etc. but with their real filenames, and 5,000+ of them, in plain
    > > text, one per line.
    > >
    > > Is there a way to turn each of these filenames into a clickable link
    > > without having to do it manually?
    > >
    > > Thanks in advance.

    >
    > put all your files in one folder, then run this at your command line.....
    >
    > <commandline>
    > FOR /F "usebackq delims==" %i IN (`dir /b`) DO @echo "<a

    href=%i>%i</a><br>"
    > >> allfiles.html

    > </commandline>
    >
    > you will now have a file called allfiles.html


    I made a file called test.bat, with:

    FOR /F "usebackq delims==" %i IN (`dir /b`) DO @echo "<a
    href=%i>%i</a><br>">> allfiles.html

    "i was unexpected at this time"

    --

    goodcow
    goodcowfilms.com
    Phillip Roncoroni, Jan 8, 2004
    #11
  12. "Jan Faerber" <> wrote in message
    news:eek:...
    >
    > > Is there a way to turn each of these filenames into a clickable link
    > > without
    > > having to do it manually?

    >
    >
    >
    >
    > Maybe you can use a simple search & replace tool.


    That wouldn't work for what I need.

    --

    goodcow
    goodcowfilms.com

    >
    >
    > Jan
    Phillip Roncoroni, Jan 8, 2004
    #12
  13. Phillip Roncoroni

    Jan Faerber Guest


    >> Maybe you can use a simple search & replace tool.

    >
    > That wouldn't work for what I need.


    Well, in Dreamweaver forinstance they have many tricks,
    but anyway:


    Or you can use a little Java programm...


    import java.io.*;

    public class URL {

    public static void main(String args[]) {

    String filename = "log.txt";
    try {
    BufferedReader in = new BufferedReader(new FileReader(filename));
    String line;
    while((line = in.readLine()) != null) {

    System.out.println("<a href=\"http://" + line + "\">" + line
    + "</a>");
    }
    in.close();
    }
    catch (IOException e) {}

    }
    }



    But you found already something. Doesn´t matter - I can post it although.

    Bye (-:




    --
    Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
    Jan Faerber, Jan 9, 2004
    #13
  14. Phillip Roncoroni

    Jan Faerber Guest


    > If you have telnet or ssh access to your server then ftp your file to the
    > server.



    .... that is a good idea - something similar would be to send the file
    in an e-mail account to yourself and then open the source code.
    The urls will be converted to html-links.

    Jan



    --
    Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
    Jan Faerber, Jan 9, 2004
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike Bridge
    Replies:
    2
    Views:
    4,693
    Mike Bridge
    Feb 20, 2004
  2. Elton Pruitt
    Replies:
    2
    Views:
    5,798
    akjoshi
    Jun 12, 2006
  3. TimmyC
    Replies:
    0
    Views:
    1,524
    TimmyC
    Jun 8, 2007
  4. geoffbache
    Replies:
    8
    Views:
    613
    Stefan Behnel
    Feb 11, 2008
  5. Alfredo Agosti
    Replies:
    3
    Views:
    346
    Aaron Bertrand - MVP
    Sep 19, 2003
Loading...

Share This Page