Possible Duplicate:
how to use javascript to open a folder and list html file names in that?
On my local Windows computer, I have a folder with a bunch of .htm files.
I would like to create "table-of-contents.html", which would link to all the .htm files in this folder.For example, if my folder 开发者_如何转开发contains these files:
apple.htm
pear.htm
banana.htm
then my table-of-contents would contain:
<a href="./apple.htm">Apple</a>
<a href="./pear.htm">Pear</a>
<a href="./banana.htm">Banana</a>
Of course I could do this manually, but I am looking for a solution that automatically generates the table-of-contents from the current folder. (This would be a component of a larger script that parses the filenames and reorganizes the links based on the parsed information.)
Any suggestions? For example, is there a way to use jquery or javascript to generate a list of the htm files in the current folder?
Using a Windows batch script, you could also do:
@echo off
echo ^<html^> > toc
for %%i in (*.htm) do echo ^<a href="./%%~nxi"^>%%~ni^</a^> >> toc
echo ^</html^> >> toc
ren toc toc.html
If you are willing to use awk / gawk.exe ( http://gnuwin32.sourceforge.net/packages/gawk.htm ), you could use the following to create the file:
dir | gawk.exe 'BEGIN { print "<html>"} { print "<a href=\"./" $1 "\">"$1"</a><br>" } END {print "</html>"}' > directory_listing.html
If you're really set on using Javascript, you can probably do something similar in Javascript as well, using regex functions, but would not be able to run it in the browser.
精彩评论