-   Programming (
-   -   Script to create index.html file (

seashell11 09-25-2010 09:59 AM

Script to 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

ghostdog74 09-25-2010 10:05 AM


Originally Posted by seashell11 (Post 4108674)
I need a script that can do this:

so basically you need someone to do all those stuff for you, right?


What would be the best way to do this?
Start to learn a programming language if you have not. That's the best way. If you do not have one in mind, i recommend Python or shell scripting.

seashell11 09-25-2010 10:08 AM

I don't need anyone to do all of this for me. If someone would just point me in the right direction, I am quite capable of figuring stuff out on my own.

GrapefruiTgirl 09-25-2010 10:17 AM

Since I know bash/shell and not Python, bash would be my personal choice.

In my script, I'd (this is very rough) 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'd use `find` again (with a -maxdepth of 1) to locate all directories & html files present; then I'd create the index.html file, and insert (probably just using `echo`) a <href=link> or whatever, to each directory and/or html file present within my current directory.

Again, this is a pretty rough draft, but I think the idea is a decent one though pretty simplified in my description.

Once you begin to come up with some code and posting it for us to see where you're at, we can help you further with problem areas that you run into.

NOTE: You probably want to set up a testing directory tree, on which to test your script or program as it develops. I would actually have a testing tree, which I would copy to a second location on which to test my program; after each test run, I'd delete the copy of the testing tree and replace it fresh with a new copy, after having examined the results of the program run.

Good luck!

seashell11 09-25-2010 10:25 AM

Thank you. This gives me a good start. If I need any more help, I will post back with the code that I have so far, and the results I am getting.

All times are GMT -5. The time now is 12:58 AM.