Generating links from "filename.htm" plain text?

  • Thread starter Phillip Roncoroni
  • Start date
P

Phillip Roncoroni

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.
 
L

Leif K-Brooks

Phillip said:
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";
 
P

Phillip Roncoroni

Leif K-Brooks said:
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...
 
H

Hunter

Phillip Roncoroni said:
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
 
H

Hunter

Hunter said:
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 (e-mail address removed)
 
D

Disco Octopus

Phillip said:
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>

you will now have a file called allfiles.html
 
J

Jan Faerber

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
 
T

Toby A Inkster

Leif said:
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";
 
L

Leif K-Brooks

Toby said:
<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.
 
P

Phillip Roncoroni

Hunter said:
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 (e-mail address removed)

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.
 
P

Phillip Roncoroni

Disco Octopus said:
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
</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"
 
J

Jan Faerber

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 (-:
 
J

Jan Faerber

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top