LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-15-2007, 05:43 AM   #1
mohan34u
LQ Newbie
 
Registered: May 2007
Posts: 2

Rep: Reputation: 0
webtree.bash - a script to create entire directory links in HTML


Hi,

I am mohan. I wish to share a script that will create an entire directory links in a HTML page. here is the script..


#! /bin/sh
# webtree.bash - directory structure listing in HTML

# creating HTML tags

echo "<html>
<head><title>$1/`basename $1`.html</title>
</head>
<body bgcolor='orange'>" > $1/`basename $1`.html

# creating links to the files in directory tree

for i in `find $1`
do
if test -d $i
then
echo "<br><br>$i<br>" >> $1/`basename $1`.html
else
echo "<br><a href='$i'>$i</a>" >> $1/`basename $1`.html
fi
done

# creating end tags for HTML

echo "</body>
</html>" >> $1/`basename $1`.html
echo $1/`basename $1`.html completed
sed -e "s:<a href='$1/:<a href=':g" $1/`basename $1`.html > tmp.html
rm $1/`basename $1`.html
mv tmp.html $1/`basename $1`.html
unset i

#run as
# $webtree.bash directory

This is my first script. Hope this script will be useful to someone. Forgive gurus if I made any mistakes in this script and correct me. my mail is mohan34u@freeshells.ch.

Thank you.

Always,
Mohan R
 
Old 07-15-2007, 08:07 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Here is something you might want to try to produce the beginning of the html page.

cat <<EOF >${1}.html
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>${1} Links</title>
</head>
<body>
EOF
[/code]
It uses a here document.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script to strip a certain directory out of directories in a directory? rylan76 Linux - General 3 08-29-2006 11:35 AM
Script or Simple App to Create HTML Table Populated With Images infidel Linux - Software 14 06-07-2005 01:08 AM
script needed: directory -> html with links to all files in dire flamesrock Linux - Software 2 03-22-2005 01:47 AM
Bash script for correcting HTML tags hq4ever Programming 4 11-08-2004 04:06 AM
Magic script to create rc.d links Rachel Carter Linux - Distributions 2 02-02-2003 02:47 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration