Linux Script create index.html file

I need a script that can do this:

  • A script that searches all directories and subdirectories for .html files
  • When a .html file is found it creates a index.html file in that folder.
  • It then edits the index.html file and inserts links to all of the .html files that are in that folder into the body.
  • If no .html files are found, it searches for folders.
  • It then creates a index.html file with links to all of the folders.

What would be the best way to do this? Do you need more information?

Thank You

Are we doing your homework? How far have you gotten?

I haven't did much with scripts before. I am still researching best ways to do it.

Here is how I was thinking I will do it, but I haven't got the script written yet:

Use the `find` command to locate every directory within the parent tree, including the top directory. Then, inside every one of the found directories, I will use `find` again (with a -maxdepth of 1) to locate all directories & html files present; then I'll create the index.html file, and insert (probably just using `echo`) a <href=link> to each directory and/or html file present within my current directory.

I'll get you started a bit.

 find / | grep *.html 

You'll have to do a foreach on the above to get this part. For the actual writing of the file

 echo "<a href\=$_>$_<\/a>"  >> destination.html" 

I don't want to give you all the answers. Just trying to help out with syntaxes.

Thank You. And no, this is not for homework. It is for a personal web server that I set up so that I can watch all of my movies in WebM format with my laptop. I already wrote a script that finds all of the WebM files and creates a html file for each webm file so that I can view them. Now I just am figuring out how to make indexes of all of the files.

Some hints for you.

A script that searches all directories and subdirectories for .html files

find /ALL_DIRECTORIES -name "*.html" -type f -print 

When a .html file is found it creates a index.html file in that folder.

find /ALL_DIRECTORIES -name "*.html" -type f -exec dirname {} \; |sort -u |while read dir
do
  if [ -f "$dir"/index.html ] 
  then
     touch "$dir"/index.html
  fi
done

for rest, you need tell us what type of links you need write in the index.html files for these .html files and folders.