包含指向文件夹中所有.htm文件的链接的目录[复制]

时间:2022-05-17 02:08:28

Possible Duplicate:
how to use javascript to open a folder and list html file names in that?

可能重复:如何使用javascript打开文件夹并列出html文件名?

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.

在我的本地Windows计算机上,我有一个包含一堆.htm文件的文件夹。我想创建“table-of-contents.html”,它将链接到此文件夹中的所有.htm文件。

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?

有什么建议么?例如,有没有办法使用jquery或javascript生成当前文件夹中的htm文件列表?

2 个解决方案

#1


2  

Using a Windows batch script, you could also do:

使用Windows批处理脚本,您还可以执行以下操作:

@echo off
echo ^<html^> > toc
for %%i in (*.htm) do echo ^<a href="./%%~nxi"^>%%~ni^</a^> >> toc
echo ^</html^> >> toc
ren toc toc.html

#2


1  

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:

如果您愿意使用awk / gawk.exe(http://gnuwin32.sourceforge.net/packages/gawk.htm),可以使用以下命令创建文件:

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.

如果您真的开始使用Javascript,您可以使用正则表达式函数在Javascript中执行类似操作,但无法在浏览器中运行它。

#1


2  

Using a Windows batch script, you could also do:

使用Windows批处理脚本,您还可以执行以下操作:

@echo off
echo ^<html^> > toc
for %%i in (*.htm) do echo ^<a href="./%%~nxi"^>%%~ni^</a^> >> toc
echo ^</html^> >> toc
ren toc toc.html

#2


1  

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:

如果您愿意使用awk / gawk.exe(http://gnuwin32.sourceforge.net/packages/gawk.htm),可以使用以下命令创建文件:

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.

如果您真的开始使用Javascript,您可以使用正则表达式函数在Javascript中执行类似操作,但无法在浏览器中运行它。